//
//  UIScrollView+XVAdd.m
//  fastservice
//
//  Created by xuning on 2/3/24.
//  Copyright © 2024 FastService. All rights reserved.
//

#import "UIScrollView+XVAdd.h"
@implementation UICollectionView (XVAdd)
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
    
    if ([self panBack:gestureRecognizer]) {
        return YES;
    }
    return NO;
    
}
-(BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
    
    if ([self panBack:gestureRecognizer]) {
        return NO;
    }
    return YES;
    
}

- (BOOL)panBack:(UIGestureRecognizer *)gestureRecognizer {
    
    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];
            if (point.x > 0 && location.x < 90 && self.contentOffset.x <= 0) {
                return YES;
            }
        }
    }
    return NO;
    
}


@end

@implementation UIScrollView (XVAdd)

//重写touchesBegin方法
//
//-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
//    
//    //主要代码实现：
//    
//    [[self nextResponder] touchesBegan:touches withEvent:event];
//    
//    //super调用，别漏
//    
//    [super touchesBegan:touches withEvent:event];
//    
//}
//
//
//
////重写touchesEnded方法
//
//- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
//    
//    [[self nextResponder] touchesEnded:touches withEvent:event];
//    
//    [super touchesEnded:touches withEvent:event];
//    
//}
//
//
//
////重写touchesMoved方法
//
//-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
//    
//    [[self nextResponder] touchesMoved:touches withEvent:event];
//    
//    [super touchesMoved:touches withEvent:event];
//    
//}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
    
    if ([self panBack:gestureRecognizer]) {
        return YES;
    }
    return NO;
    
}
-(BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
    
    if ([self panBack:gestureRecognizer]) {
        return NO;
    }
    return YES;
    
}

- (BOOL)panBack:(UIGestureRecognizer *)gestureRecognizer {
    
    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];
            if (point.x > 0 && location.x < 90 && self.contentOffset.x <= 0) {
                return YES;
            }
        }
    }
    return NO;
    
}



@end
