Search code examples
iosswiftswift3uinavigationcontrolleruigesturerecognizer

UINavigationController change InteractivePopGesture direction


I am designing a right to left application.I've made everything rtl by using this line of code:

UIView.appearance().semanticContentAttribute = .forceRightToLeft

and that works correct for everything expect the interactive pop gesture of my navigation controller. the direction of the segue is correct:

enter image description here

but when I want to use the pop gesture (swipe from left edge to right edge) the view become visible from opposite side.
How should I change it?
I've tried changing the edges to .right but that disabled the gesture recognizer :

let gesture = interactivePopGestureRecognizer as! UIScreenEdgePanGestureRecognizer
    gesture.edges = .right

Solution

  • You should change the both view and navigationBar semantic attribute
    use this extension:

    extension UIViewController {
        open override func awakeFromNib() {
            super.awakeFromNib()
            navigationController?.view.semanticContentAttribute = .forceRightToLeft
            navigationController?.navigationBar.semanticContentAttribute = .forceRightToLeft
        }
    }