禁止navigationController左滑手势

在禁止左滑的viewController的viewDidAppear里设置:

- (void)viewDidAppear:(BOOL)animated
{

   [super viewDidAppear:animated];

   if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) 
{

//这里对添加到右滑视图上的所有手势“禁用”

    for (UIGestureRecognizer *popGesture in self.navigationController.interactivePopGestureRecognizer.view.gestureRecognizers)    {

     popGesture.enabled = NO;

  }

}

}

如果仅仅是想禁止当前页面的左滑手势,还需要在viewWillDisappear里设置:

- (void)viewWillDisappear:(BOOL)animated

{

    [super viewWillDisappear:animated];

    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {

        //这里对添加到右滑视图上的所有手势“启用”

        for (UIGestureRecognizer *popGesture in self.navigationController.interactivePopGestureRecognizer.view.gestureRecognizers) {

            popGesture.enabled = YES;

        }

    }

}

猜你喜欢

转载自blog.csdn.net/wyz670083956/article/details/124275580