我用过这个。
self.navigationController.interactivePopGestureRecognizer.delegate = self;
在我的 UINavigationController 类中也可以在转换期间禁用 interactivePopGestureRecognizer。
- (void)pushViewController:(UIViewController *)viewController
animated:(BOOL)animated
{
if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.interactivePopGestureRecognizer.enabled = NO;
}
[super pushViewController:viewController animated:animated];
}
- (void)navigationController:(UINavigationController *)navigationController
didShowViewController:(UIViewController *)viewController
animated:(BOOL)animated
{
if ([navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
// disable interactivePopGestureRecognizer in the rootViewController of navigationController
if ([[navigationController.viewControllers firstObject] isEqual:viewController]) {
navigationController.interactivePopGestureRecognizer.enabled = NO;
} else {
// enable interactivePopGestureRecognizer
navigationController.interactivePopGestureRecognizer.enabled = YES;
}
}
}
在rootViewController中禁用interactivePopGestureRecognizer的原因是:当从rootViewController的边缘滑动,然后点击一些东西来推送下一个viewController,UI现在不会接受任何触摸。按home键将应用程序置于后台,然后点击进入前景...