@property(nullable, nonatomic, readonly) UIGestureRecognizer *interactivePopGestureRecognizer
当你想禁用某一个页面的滑动返回,我们只需要设置
self.navigationController.interactivePopGestureRecognizer.enabled = NO;就好了。
习惯性的我们基本都会这样写:
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
}
- (void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
self.navigationController.interactivePopGestureRecognizer.enabled = YES;
}
然而一个奇妙的bug就发生了明明恢复了navigationController的禁用,但是self.navigationController.interactivePopGestureRecognizer.enabled = YES;似乎不起作用。push的页面也能滑动返回了。其实不是设置无效,而是self.navigationController.interactivePopGestureRecognizer.enabled = NO;又把它禁掉了。你准备滑动返回时,因为生命周期的缘故,滑动手势正在响应,上个viewWillAppear中self.navigationController.interactivePopGestureRecognizer.enabled = NO也就会取消了正在响应的手势,造成一定的卡死。知道了原因我们只需要延缓手势被禁用的时机即可
- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
}