iOS 左滑手势与 ScrollView 冲突

新建自定义ScrollView  加入代码

- (BOOL)gestureRecognizer:(UIGestureRecognizer*)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer*)otherGestureRecognizer {


    if([selfpanBack:gestureRecognizer]) {

        returnYES;

    }

    return NO;


}

//location_X可自己定义,其代表的是滑动返回距左边的有效长度

- (BOOL)panBack:(UIGestureRecognizer*)gestureRecognizer {


    //是滑动返回距左边的有效长度

    intlocation_X =40;


    if(gestureRecognizer ==self.panGestureRecognizer) {

        UIPanGestureRecognizer *pan = (UIPanGestureRecognizer *)gestureRecognizer;

        CGPointpoint = [pantranslationInView:self];

        UIGestureRecognizerStatestate = gestureRecognizer.state;

        if (UIGestureRecognizerStateBegan == state ||UIGestureRecognizerStatePossible == state) {

            CGPointlocation = [gestureRecognizerlocationInView:self];


            //这是允许每张图片都可实现滑动返回

            //            int temp1 = location.x;

            //            int temp2 = KScreenW;

            //            NSInteger X = temp1 % temp2;

            //            if (point.x >0 && X < location_X) {

            //                return YES;

            //            }

            //下面的是只允许在第一张时滑动返回生效

            if(point.x>0&& location.x< location_X &&self.contentOffset.x<=0) {

                returnYES;

            }

        }

    }

    return NO;


}

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer*)gestureRecognizer {


    if([selfpanBack:gestureRecognizer]) {

        returnNO;

    }

    return YES;


}

你可能感兴趣的:(iOS 左滑手势与 ScrollView 冲突)