For example: My heel controller is a navigation controller, and now there is a controller A that I pushed over. I hope that this controller can only pop by clicking the return button on the left side of the navigation bar, and slide right on the side. I hope to disable the pop gesture. Of course, I hope other controllers don’t still have this pop gesture. Please tell me how to implement this change?
高洛峰2017-05-02 09:31:05
Write in controller A:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.navigationController.interactivePopGestureRecognizer.delegate = self;
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
self.navigationController.interactivePopGestureRecognizer.delegate = nil;
}
// 给该控制器添加协议 <UIGestureRecognizerDelegate>
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
return gestureRecognizer != self.navigationController.interactivePopGestureRecognizer;
}
伊谢尔伦2017-05-02 09:31:05
If the construction from A -> B is more elegant
Inside B’s viewDidLoad
self.navigationController.interactivePopGestureRecognizer.delegate = self;
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
[super pushViewController:viewController animated:animated];
self.interactivePopGestureRecognizer.enabled = NO;
}
Then inside viewDidDisappear
self.navigationController.interactivePopGestureRecognizer.enabled = YES;
It’s all written in B, isn’t it much more elegant