objective-c - 请问如何禁用当前控制器的侧边右滑pop手势?当前VC是push过来的
習慣沉默
習慣沉默 2017-05-02 09:29:05
0
2
566

如题:我的跟控制器是是个导航控制器,现在有一个A控制器是我push过来的,我希望这个控制器只能点击导航条左边的返回按钮来pop,而侧边右滑动的手势pop我希望能把它禁用掉。当然其他控制器我希望不还是有这个pop的手势。请问我改如何实现呢?

習慣沉默
習慣沉默

Antworte allen(2)
小葫芦

在 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;
}
伊谢尔伦

建设从 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 里面,是不是优雅了许多

Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage