美文网首页
解决一级页面手势返回页面卡死

解决一级页面手势返回页面卡死

作者: Treey_Ahao | 来源:发表于2018-02-25 11:14 被阅读0次

    今天在测试程序的时候发现一个bug,在一级页面左右滑动后,再点击页面按钮页面会卡死,原因是一级页面没有上级页面,必须禁掉手势返回。

    #pragma mark *********解决一级页面手势返回卡死的情况**********
    - (void)viewDidAppear:(BOOL)animated
    {
        [super viewDidAppear:animated];
        if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)])
        {
            self.navigationController.interactivePopGestureRecognizer.enabled = NO;
        }
    }
    - (void)viewDidDisappear:(BOOL)animated
    {
        if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)])
        {
            self.navigationController.interactivePopGestureRecognizer.enabled = YES;
        }
    }
    

    方法二:

    #pragma mark *********解决一级页面手势返回卡死的情况**********
    - (void)viewDidAppear:(BOOL)animated
    {
        [super viewDidAppear:animated];
        self.isCanSideBack = NO;
        if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)])
        {
            self.navigationController.interactivePopGestureRecognizer.delegate=self;
        }
    }
    
    - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer*)gestureRecognizer {
    
       return self.isCanSideBack;
    }
    
    - (void)viewDidDisappear:(BOOL)animated
    {
        self.isCanSideBack=YES;
        if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)])
        {
            self.navigationController.interactivePopGestureRecognizer.delegate = nil;
        }
    }
    

    实现- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer*)gestureRecognizer需要继承 <UIGestureRecognizerDelegate>协议,是系统自己调用的!

    相关文章

      网友评论

          本文标题:解决一级页面手势返回页面卡死

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