9

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.

Community
  • 1
  • 1
jeffwong
  • 335
  • 2
  • 9
  • possible duplicate of [iOS 7 use custom interactive transitions only some of the time](http://stackoverflow.com/questions/20113701/ios-7-use-custom-interactive-transitions-only-some-of-the-time) – jszumski Feb 03 '15 at 19:07

2 Answers2

6

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.

Community
  • 1
  • 1
jamesk
  • 3,807
  • 21
  • 38
  • Thank you this is what I was looking for. Now I can go for a custom navigation bar for my app. – Leena Jul 23 '18 at 07:58
1

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

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

Community
  • 1
  • 1
yonel
  • 7,855
  • 2
  • 44
  • 51