navigationController.interactivePopGestureRecognizer.enabled = NO;
具体代码如下
在 viewDidLoad方法中设置
self.navigationController.delegate = self;
__weak typeof (self)weakSelf = self;
if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
// self.interactivePopGestureRecognizer.enabled = YES;
/* UIGestureRecognizerDelegate */
self.navigationController.interactivePopGestureRecognizer.delegate = weakSelf;
}
然后设置回调方法
- (void)navigationController:(UINavigationController* )navigationController didShowViewController:(UIViewController* )viewController animated:(BOOL)animated
{
if ([navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
navigationController.interactivePopGestureRecognizer.enabled = YES;
}
// if rootViewController, set delegate nil /
if (navigationController.viewControllers.count == 1) {
navigationController.interactivePopGestureRecognizer.enabled = NO;
}
}