问题记录:在做了部分页面的转场动画之后,返回手势不灵了,快速连续返回的话会卡住,App退到后台再重新激活之后页面不卡了,但是UI错乱.
解决方案:
1. 在UINavigationController子类实现代理UIGestureRecognizerDelegate,并在viewDidLoad方法中增加代理设置:
- (void)viewDidLoad {[super viewDidLoad];self.interactivePopGestureRecognizer.delegate = self; }
2. 重写UINavigationController的push方法,在方法中关闭手势:
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {if (self.viewControllers.count > 0) {viewController.hidesBottomBarWhenPushed = YES;}// 为了解决部分页面加了转场动画手势返回卡死的bug// 在UINavigationController代理方法didShowViewController中设置enable = YESif ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {self.interactivePopGestureRecognizer.enabled = NO;}[super pushViewController:viewController animated:animated];}
3. 在UINavigationControllerDelegate代理类中实现navigationController:didShowViewController:animated:方法:
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {// 为了解决手势返回卡住的bug// 在NavigationController中重写push方法禁用返回手势,此处打开if ([navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {navigationController.interactivePopGestureRecognizer.enabled = YES;} }