Hibit_iOS/HiBit/Project/Player/View/GKDYScrollView.m
2024-06-11 10:51:38 +08:00

59 lines
2.1 KiB
Objective-C
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// GKDYScrollView.m
// GKDYVideo
//
// Created by QuintGao on 2018/9/23.
// Copyright © 2018 QuintGao. All rights reserved.
//
#import "GKDYScrollView.h"
@implementation GKDYScrollView
#pragma mark - 解决全屏滑动时的手势冲突 与 左滑push手势冲突
// 当UIScrollView在水平方向滑动到第一个时默认是不能全屏滑动返回的通过下面的方法可实现其滑动返回。
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
if ([self panBack:gestureRecognizer]) {
return NO;
}
return YES;
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
if ([self panBack:gestureRecognizer]) {
return YES;
}
return NO;
}
- (BOOL)panBack:(UIGestureRecognizer *)gestureRecognizer {
if (gestureRecognizer == self.panGestureRecognizer) {
CGPoint point = [self.panGestureRecognizer translationInView:self];
UIGestureRecognizerState state = gestureRecognizer.state;
// 设置手势滑动的位置距屏幕左边的区域
CGFloat locationDistance = self.bounds.size.width;
if (state == UIGestureRecognizerStateBegan || state == UIGestureRecognizerStatePossible) {
CGPoint location = [gestureRecognizer locationInView:self];
if (point.x > 0 && location.x < locationDistance && self.contentOffset.x <= 0) {
return YES;
}
// 临界点scrollView滑动到最后一屏时的x轴位置可根据需求改变
CGFloat criticalPoint = self.frame.size.width;
// point.x < 0 代表左滑即手指从屏幕右边向左移动
// 当UIScrollview滑动到临界点时则不再相应UIScrollview的滑动左滑手势防止与左滑手势冲突
if (point.x < 0 && self.contentOffset.x + criticalPoint >= self.contentSize.width) {
return YES;
}
}
}
return NO;
}
@end