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!
Swift 3:
Setting a custom back button disable the swipe back feature.
The best thing to do to keep it is to subclass
UINavigationViewController
and set itself as theinteractivePopGestureRecognizer
delegate; then you can return YES fromgestureRecognizerShouldBegin
to allow the swipe back.For example, this is done in AHKNavigationController
And a Swift version here: https://stackoverflow.com/a/43433530/308315
it works for me Swift 3:
and in ViewDidLoad: