Rumah > Soal Jawab > teks badan
如题:我的跟控制器是是个导航控制器,现在有一个A控制器是我push过来的,我希望这个控制器只能点击导航条左边的返回按钮来pop,而侧边右滑动的手势pop我希望能把它禁用掉。当然其他控制器我希望不还是有这个pop的手势。请问我改如何实现呢?
高洛峰2017-05-02 09:31:05
Tulis dalam pengawal 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
Bangunan dari A -> B lebih elegan
Di dalam viewDidLoad B
self.navigationController.interactivePopGestureRecognizer.delegate = self;
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
[super pushViewController:viewController animated:animated];
self.interactivePopGestureRecognizer.enabled = NO;
}
Kemudian dalam viewDidDisappear
self.navigationController.interactivePopGestureRecognizer.enabled = YES;
Semuanya ditulis dalam B, bukankah lebih elegan?