I found the solution for it after searching long time, if someone seeks.
The reason that the UI freezes / hangs is because the UINavigationController is missing a check for the root view controller when the gesture is executed on the root view. There a few ways to fix that, the following is what I did.
You should subclass UINavigationController, this is the right way to go and add implement as followed:
class RTLNavController: UINavigationController, UINavigationControllerDelegate, UIGestureRecognizerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
// Adding swipe to pop viewController
self.interactivePopGestureRecognizer?.isEnabled = true
self.interactivePopGestureRecognizer?.delegate = self
// UINavigationControllerDelegate
self.delegate = self
}
func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
navigationController.view.semanticContentAttribute = UIView.isRightToLeft() ? .forceRightToLeft : .forceLeftToRight
navigationController.navigationBar.semanticContentAttribute = UIView.isRightToLeft() ? .forceRightToLeft : .forceLeftToRight
}
// Checking if the viewController is last, if not disable the gesture
func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
if self.viewControllers.count > 1 {
return true
}
return false
}
}
extension UIView {
static func isRightToLeft() -> Bool {
return UIView.appearance().semanticContentAttribute == .forceRightToLeft
}
}
Resources:
Original question:
The answer is used for the solution:
Other solution which may work better (But it's in Objective-C):