美文网首页
解决MMDrawerController和UIScrollVie

解决MMDrawerController和UIScrollVie

作者: CJ阿杰 | 来源:发表于2018-03-30 00:09 被阅读16次

    当MMDrawerController的centerViewController添加UIScrollView的时候,滑动打开抽屉就失效了。我在网上找到这篇帖子https://www.2cto.com/kf/201608/543321.html跟我的问题类似,虽然我使用他的方法并没有奏效,不过按照他的思路我最终还是解决了我的问题。

    解决办法是写一个UIScrollView的子类,并实现UIGestureRecognizerDelegate中的方法

    @implementation CJScrollView
    
    - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer*)gestureRecognizer {
    
        if([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) {
            return YES;
        }
        return [super gestureRecognizerShouldBegin:gestureRecognizer];
    }
    
    - (BOOL)gestureRecognizer:(UIGestureRecognizer*)gestureRecognizer shouldRequireFailureOfGestureRecognizer:(UIGestureRecognizer*)otherGestureRecognizer {
    
        if ([gestureRecognizer isKindOfClass:NSClassFromString(@"UIScrollViewPanGestureRecognizer")] &&
            [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) {
    
            if(self.contentOffset.x==0.0f) {
                //这里返回YES,gestureRecognizer和otherGestureRecognizer互斥时,gestureRecognizer会失效
                return YES;
            }
        }
        return NO;
    }
    
    @end
    

    相关文章

      网友评论

          本文标题:解决MMDrawerController和UIScrollVie

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