美文网首页
iOS:右划返回手势与scrollView左右滑冲突

iOS:右划返回手势与scrollView左右滑冲突

作者: kindom_0129 | 来源:发表于2017-10-23 15:50 被阅读0次

    原因:

    scrollView的优先响应了手势事件,导致右划事件未响应

    解决:

    @implementation UIScrollView (BTGestureRecognizer)
    
    -(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
    {
        // 首先判断otherGestureRecognizer是不是系统pop手势
        if ([otherGestureRecognizer.view isKindOfClass:NSClassFromString(@"UILayoutContainerView")]) {
            // 再判断系统手势的state是began还是fail,同时判断scrollView的位置是不是正好在最左边
            if (otherGestureRecognizer.state == UIGestureRecognizerStateBegan && self.contentOffset.x == 0) {
                return YES;
            }
        }
        
        return NO;
    }
    
    @end
    

    相关文章

      网友评论

          本文标题:iOS:右划返回手势与scrollView左右滑冲突

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