The solution to the conflict between the controller's sliding back gesture and the UIScrollvie scroll event

// Create the Category of UIScrollview and add the code as follows


#define IPHONE_H [UIScreen mainScreen].bounds.size.height //The height of the screen

#define IPHONE_W [UIScreen mainScreen].bounds.size.width // the width of the screen

//A one-sentence summary is that when this method returns YES, the gesture event will continue to be passed down, regardless of whether the current level responds to the event.

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

    

    if ([self panBack:gestureRecognizer]) {

        return YES;

    }

    return NO;

    

}


//location_X can be defined by yourself, which represents the effective length of the sliding return from the left

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

    

    // is the effective length of the sliding return from the left

    int location_X =0.15*IPHONE_W;

    

    if (gestureRecognizer ==self.panGestureRecognizer) {

        UIPanGestureRecognizer *pan = (UIPanGestureRecognizer *)gestureRecognizer;

        CGPoint point = [pan translationInView:self];

        UIGestureRecognizerState state = gestureRecognizer.state;

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

            CGPoint location = [gestureRecognizer locationInView:self];

            

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

            int temp1 = location.x;

            int temp2 =IPHONE_W;

            NSInteger XX = temp1 % temp2;

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

                return YES;

            }

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

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

            //                return YES;

            //            }

        }

    }

    return NO;

    

}


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

    

    if ([self panBack:gestureRecognizer]) {

        return NO;

    }

    return YES;

    

}


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325563046&siteId=291194637