iOS禁用边缘侧滑返回

开发中,出于某种需求或者避免某个bug,会有要求某一个界面不能侧滑返回。这里给大家介绍一种简单的实现方法:

进入该页面时,关闭侧滑手势:

  • (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    if([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
    self.navigationController.interactivePopGestureRecognizer.enabled = NO;
    }
    }
    进入下个页面或者返回上一个页面时,启用侧滑手势:
  • (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    if([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
    self.navigationController.interactivePopGestureRecognizer.enabled = YES;
    }
    }

你可能感兴趣的:(iOS禁用边缘侧滑返回)