问题:
当A controller作为navigationController的rootcontroller时,如果在A中向右侧滑动,再push到下个界面时会出现界面假死。原因此时导航控制器的viewControllers的count值为1,滑动时没有上层控制器,系统不知如何处理,所以会出现假死。
解决方法:
自定义导航控制器,实现如下代理
- (void)viewDidLoad {
[super viewDidLoad];
__weak BaseNavigationViewController *weakSelf = self;
if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.interactivePopGestureRecognizer.delegate = weakSelf;
self.delegate = weakSelf;
}
}
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
if ( [self respondsToSelector:@selector(interactivePopGestureRecognizer)]&&animated == YES ){
self.interactivePopGestureRecognizer.enabled = NO;
}
[super pushViewController:viewController animated:animated];
}
- (NSArray *)popToRootViewControllerAnimated:(BOOL)animated {
if ( [self respondsToSelector:@selector(interactivePopGestureRecognizer)]&& animated == YES ){
self.interactivePopGestureRecognizer.enabled = NO;
}
return [super popToRootViewControllerAnimated:animated];
}
- (NSArray *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated {
if( [self respondsToSelector:@selector(interactivePopGestureRecognizer)] ){
self.interactivePopGestureRecognizer.enabled = NO;
}
return [super popToViewController:viewController animated:animated];
}
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animate {
if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]){
if (navigationController.childViewControllers.count == 1) {
self.interactivePopGestureRecognizer.enabled = NO;
}else {
self.interactivePopGestureRecognizer.enabled = YES;
}
}
}