InteractivePopGestureRecognizer导致应用程序冻结

在我的应用中,我有不同的控制器。 当我将controller1推到导航控制器并向后滑动时,一切正常。 但是,如果我按下导航控制器1,并进入controller1推控制器2并尝试向后滑动,我得到一个冻结的应用程序。 如果通过后退按钮返回一切正常。

我怎么能抓住这个问题?

使用滑动到弹出手势时,我遇到了与冻结界面类似的问题。 在我的情况下问题是在controller1.viewDidAppear我禁用滑动手势: self.navigationController.interactivePopGestureRecognizer.enabled = NO 。 因此,当用户开始从contorller2向后滑动时,触发了controller1.viewDidAppear并且在其工作期间禁用了手势。

我通过在controller1中设置self.navigationController.interactivePopGestureRecognizer.delegate = self并实现gestureRecognizerShouldBegin:来解决这个问题,而不是禁用手势识别器:

 - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer { if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)] && gestureRecognizer == self.navigationController.interactivePopGestureRecognizer) { return NO; } return YES; } 

我的解决方案是向导航控制器添加一个委托。 然后仅在根视图控制器中禁用弹出手势识别器。 因人而异。

 #pragma mark - UINavigationControllerDelegate - (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated { BOOL isRootVC = viewController == navigationController.viewControllers.firstObject; navigationController.interactivePopGestureRecognizer.enabled = !isRootVC; } 

我有同样的问题,我发现下面的解决方案。 添加以下控制器

 #import  @interface CBNavigationController : UINavigationController  @end #import "CBNavigationController.h" @interface CBNavigationController () @end @implementation CBNavigationController - (void)viewDidLoad { NSLog(@"%s",__FUNCTION__); __weak CBNavigationController *weakSelf = self; if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) { self.interactivePopGestureRecognizer.delegate = weakSelf; self.delegate = weakSelf; } } - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated { NSLog(@"%s",__FUNCTION__); if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) self.interactivePopGestureRecognizer.enabled = NO; [super pushViewController:viewController animated:animated]; } #pragma mark UINavigationControllerDelegate - (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animate { NSLog(@"%s",__FUNCTION__); // Enable the gesture again once the new controller is shown if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) self.interactivePopGestureRecognizer.enabled = YES; } @end 

可以参考下面的链接

http://keighl.com/post/ios7-interactive-pop-gesture-custom-back-button/

我的解决方案是selfImplementDelegateSystemDelegate之间的交换self.navigationController.interactivePopGestureRecognizer.delegate

 - (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [_tableView reloadData]; _oldReturnDelegate = self.navigationController.interactivePopGestureRecognizer.delegate; self.navigationController.interactivePopGestureRecognizer.delegate = self; } - (void)viewWillDisappear:(BOOL)animated { self.navigationController.interactivePopGestureRecognizer.delegate = _oldReturnDelegate; [super viewWillDisappear:animated]; } 

我建议你试试这个。 这对我来说很完美。 您仍然可以享受交互式滑动。

 - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer { if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)] && gestureRecognizer == self.navigationController.interactivePopGestureRecognizer) { if(self.navigationController.viewControllers.count<=1) { return NO; } } return YES; } 

我解决了我的问题, UINavigationController interactivePopGestureRecognizer在iOS7中工作exception并设置了self.navigationController.interactivePopGestureRecognizer.delegate = self; 在每个viewcontroller的- (void)viewWillAppear:(BOOL)animated