美文网首页
禁止侧滑返回

禁止侧滑返回

作者: SpursGo | 来源:发表于2017-08-08 15:20 被阅读60次

    方案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;
    }
    }
    

    相关文章

      网友评论

          本文标题:禁止侧滑返回

          本文链接:https://www.haomeiwen.com/subject/bcitrxtx.html