objective-c - How to disable the side right swipe pop gesture of the current controller? Currently, VC is pushed here.
習慣沉默
習慣沉默 2017-05-02 09:29:05
0
2
581

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?

習慣沉默
習慣沉默

reply all(2)
小葫芦

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

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template