禁止侧滑返回

2017-08-08  本文已影响60人  SpursGo

方案1

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    if([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.navigationController.interactivePopGestureRecognizer.enabled = NO;
    }
}

- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
    //在其他离开改页面的方法同样加上下面代码
    if([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.navigationController.interactivePopGestureRecognizer.enabled = YES;
    }
}

方案2

- (void)viewDidAppear:(BOOL)animated {
  [superviewDidAppear:animated];
  self.isCanSideBack = NO;
if([self.navigationControllerrespondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.navigationController.interactivePopGestureRecognizer.delegate=self;
}
}
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer)gestureRecognizer {
    return self.isCanSideBack;
}
- (void)viewDidDisappear:(BOOL)animated {
[superviewDidDisappear:animated];
//在其他离开改页面的方法同样加上下面两句代码
self.isCanSideBack=YES;
if([self.navigationControllerrespondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.navigationController.interactivePopGestureRecognizer.delegate = nil;
}
}
上一篇下一篇

猜你喜欢

热点阅读