如題:我的跟控制器是是個導航控制器,現在有一個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 裡面,是不是優雅了許多