When I swipe from left to right on navigation bar, my navigation controller pops a view controller. I already looked at this question so I know I can set ...
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
... but it just disables the swipe on the view below the navigation bar, not the bar itself.
My current solution is to manually find the gesture and disable it. Which works, but not sure if there's a better way. The navigation bar doesn't seem to have a property like interactivePopGestureRecognizer
.
// This is inside a `UINavigationController` subclass.
for (UISwipeGestureRecognizer *gr in self.navigationBar.gestureRecognizers) {
if ([gr isKindOfClass:[UISwipeGestureRecognizer class]] && gr.direction == UISwipeGestureRecognizerDirectionRight) {
gr.enabled = NO;
}
}
The UIGestureRecognizerDelegate
has a method called - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
.
If you are able to point out if the touch's view is the UINavigationBar
, just make it return "NO".
Such Like
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
return (![[[touch view] class] isSubclassOfClass:[UIControl class]]); // UIControl is whatever as you like.
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With