I want to disable the pop gesture on swiping the viewcontroller but the below lines are not working in iOS 8:
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
Thanks in Advance
I want to disable the pop gesture on swiping the viewcontroller but the below lines are not working in iOS 8:
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
Thanks in Advance
In the viewcontroller that you want it to be disabled, add the following line:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.navigationController.interactivePopGestureRecognizer.delegate = self;
}
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.navigationController.interactivePopGestureRecognizer.delegate = nil;
}
}
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
return NO;
}
I use this solution in my project, it disables only interactivePopGestureRecognizer and allows you to use another gesture recognizers.
- (void)viewDidLoad {
[super viewDidLoad];
if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
self.navigationController.interactivePopGestureRecognizer.delegate = self;
}
}
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
if ([gestureRecognizer isEqual:self.navigationController.interactivePopGestureRecognizer]) {
return NO;
} else {
return YES;
}
}
Following solution!!!
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
__weak id weakSelf = self;
self.navigationController.interactivePopGestureRecognizer.delegate = weakSelf; }
The navigation controller installs this gesture recognizer on its view and uses it to pop the topmost view controller off the navigation stack. You can use this property to retrieve the gesture recognizer and tie it to the behavior of other gesture recognizers in your user interface. When tying your gesture recognizers together, make sure they recognize their gestures simultaneously to ensure that your gesture recognizers are given a chance to handle the event.
Usually we need to implement when you manually add a Navigation Bar or when we customized Navigation Controller
Add on RootViewController the protocol UIGestureRecognizerDelegate and viewWillAppear add:
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.interactivePopGestureRecognizer!.delegate = self }
- (void)viewDidLoad {
[super viewDidLoad];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
});
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
self.navigationController.interactivePopGestureRecognizer.enabled = YES;
});
}
I think the easy way is above. You should not make gesture enable directly in viewDidLoad()。 But you can change it's state after viewDidAppeared(). You know it's After, :-D