How to disable direct gesture on UINavigationBar?

When I sit down from left to right in the navigation bar, my navigation controller pushes out the view controller. I already looked at this question , so I know that I can install ...

self.navigationController.interactivePopGestureRecognizer.enabled = NO;

... but it just disables scrolling in the view under the navigation bar, not in the bar itself.

My current solution is to manually find the gesture and turn it off. Which works, but not sure if there is a better way. The navigation bar does not seem to have the same property as 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; } } 
+6
source share
1 answer

UIGestureRecognizerDelegate has a method - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch . If you can indicate if there is a touch view of the UINavigationBar , just return it to NO .

Like

 - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { return (![[[touch view] class] isSubclassOfClass:[UIControl class]]); // UIControl is whatever as you like. } 
+3
source

All Articles