Closed txie closed 11 years ago
You can remove the pan gesture recognizer from the navigation controller's navigation bar for the views that you wish to disable that feature. You'll have to hold a reference to it (or recreate it) if you want to add it back later.
Thanks, here is what I do:
- (void)viewWillAppear:(BOOL)animated {
// enable pan gesture
NSArray* gestureRecognizers = [self.navigationController.navigationBar gestureRecognizers];
for (UIGestureRecognizer *gestureRecognizer in gestureRecognizers) {
if ([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) {
gestureRecognizer.enabled = YES;
break;
}
}
}
NSArray* gestureRecognizers = [self.navigationController.navigationBar gestureRecognizers];
for (UIGestureRecognizer *gestureRecognizer in gestureRecognizers) {
if ([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) {
gestureRecognizer.enabled = NO;
break;
}
}
It works OK, but is there any better ways?
That seems about as simple as it can get. The only other thing I can think of is you could make it a method:
- (void)enableSwipeToRevealGesture:(BOOL)enable {
NSArray* gestureRecognizers = [self.navigationController.navigationBar gestureRecognizers];
for (UIGestureRecognizer *gestureRecognizer in gestureRecognizers) {
if ([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) {
gestureRecognizer.enabled = enable;
break;
}
}
}
so it doesn't clutter your logic flow.
I found if I have a navigation controller which has a wizard like a few steps, user swipe to navigation bar and reveal the side menu can be confusing. If there anyway to disable that, and make user can reveal side menu only at root view controller only?
Thanks.