如题:我的跟控制器是是个导航控制器,现在有一个A控制器是我push过来的,我希望这个控制器只能点击导航条左边的返回按钮来pop,而侧边右滑动的手势pop我希望能把它禁用掉。当然其他控制器我希望不还是有这个pop的手势。请问我改如何实现呢?
高洛峰2017-05-02 09:31:05
在 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
建设从 A -> B 优雅一点的话
在 B 的 viewDidLoad 里面
self.navigationController.interactivePopGestureRecognizer.delegate = self;
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
[super pushViewController:viewController animated:animated];
self.interactivePopGestureRecognizer.enabled = NO;
}
然后在 viewDidDisappear 里面
self.navigationController.interactivePopGestureRecognizer.enabled = YES;
都写在 B 里面,是不是优雅了许多