I got the opposite issue from here.
By default in iOS7
, back swipe gesture of UINavigationController
's stack could pop the presented ViewController
. Now I just uniformed all the self.navigationItem.leftBarButtonItem
style for all the ViewControllers
.
Here is the code:
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:LOADIMAGE(@"back_button") style:UIBarButtonItemStylePlain target:self action:@selector(popCurrentViewController)];
after that, the navigationController.interactivePopGestureRecognizer
is disabled. How could I make the pop gesture enabled without removing the custom leftBarButtonItem
?
Thanks!
First set delegate in viewDidLoad:
And then disable gesture when pushing:
And enable in viewDidDisappear:
This answer, but with storyboard support.
You need to handle two scenarios:
If you just need a base class you can use, here's a Swift 3 version:
If you end up needing to act as a
UINavigationControllerDelegate
in another class, you can write a delegate forwarder similar to this answer.Adapted from source in Objective-C: https://github.com/fastred/AHKNavigationController
This is the best way to enable/ disable swipe to pop view controller in iOS 10, Swift 3 :
For First Screen [ Where you want to Disable Swipe gesture ] :
For middle screen [ Where you want to Enable Swipe gesture ] :
For those who are still having trouble with this, try separating the two lines as below.
Obviously, in my app,
got reset to
false
before the view was shown for some reason.It works for me when I set the delegate
and then implement