Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UINavigationController custom animation prevents swipe-to-go-back from working

I noticed something strange and may possibly be a bug in UINavigationController. When you override -navigationController:animationControllerForOperation:fromViewController:toViewController:

and return nil (for the default animation behavior), the drag-to-go-back gesture no longer works. The documentation for this method says you should return " nil if you want to use the standard navigation controller transitions". My reading of this is that returning nil should not prevent the default behavior from happening.

I also found that if the navigation controllers's interactivePopGestureRecognizer.delegate with something that returns YES for gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer: The pop gesture works again. However, this workaround is risky since we are stomping on the default delegate that is installed, which is a _UINavigationInteractiveTransition.

Is there someway I can override the animationController method while retaining the default drag-to-go-back gesture?

This question is related.

like image 888
jeffwong Avatar asked Aug 28 '14 21:08

jeffwong


2 Answers

If you've subclassed UINavigationController, the simplest fix is as follows (iOS 9.3, Swift 2.2):

override func viewDidLoad() {
    super.viewDidLoad()
    interactivePopGestureRecognizer?.delegate = nil
}

Alternatively, in any other instance of UIViewController:

override func viewDidLoad() {
    super.viewDidLoad()
    navigationController?.interactivePopGestureRecognizer?.delegate = nil
}

Implementing the delegate method navigationController(_:animationControllerFor:from:to:) disables the navigation controller's interactive pop gesture recognizer, but setting the gesture's delegate to nil re-enables it.

If you only want the gesture to be enabled in particular circumstances, see this answer.

like image 60
jamesk Avatar answered Nov 03 '22 19:11

jamesk


This SO question is about the same subject and this answer may fix the issue :

https://stackoverflow.com/a/20923477/145710

like image 39
yonel Avatar answered Nov 03 '22 21:11

yonel