美文网首页
iOS禁用边缘侧滑返回

iOS禁用边缘侧滑返回

作者: 涛歌依旧 | 来源:发表于2018-01-27 21:18 被阅读0次

    开发中,出于某种需求或者避免某个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禁用边缘侧滑返回

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