| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- //
- // MOMsgCustomTwoTableView.m
- // MiMoLive
- //
- // Created by SuperC on 2024/3/28.
- //
- #import "MOMsgCustomTwoTableView.h"
- @interface MOMsgCustomTwoTableView ()<UIGestureRecognizerDelegate>
- @end
- @implementation MOMsgCustomTwoTableView
- {
- // UIPanGestureRecognizer *_panGesture;
- // CGPoint _startContentOffset;
- // CGPoint _startPanLocation;
- // NSTimeInterval _lastUpdateTime;
- // CGFloat _lastSpeed;
- // CGFloat _scrollDuration;
- // BOOL _isScrolling;
- //
- // CGPoint _lastContentOffset;
- // BOOL _isDragging;
- // BOOL _isDecelerating;
- }
- - (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style {
- self = [super initWithFrame:frame style:style];
- if (self) {
- // _panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGesture:)];
- // _panGesture.delegate = self;
- // [self addGestureRecognizer:_panGesture];
- }
- return self;
- }
- - (void)awakeFromNib{
- [super awakeFromNib];
-
- // _panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGesture:)];
- // _panGesture.delegate = self;
- // [self addGestureRecognizer:_panGesture];
- }
- //- (void)handlePanGesture:(UIPanGestureRecognizer *)gesture {
- // switch (gesture.state) {
- // case UIGestureRecognizerStateBegan:
- // [self panGestureBegan:gesture];
- // break;
- // case UIGestureRecognizerStateChanged:
- // [self panGestureChanged:gesture];
- // break;
- // case UIGestureRecognizerStateEnded:
- // case UIGestureRecognizerStateCancelled:
- // [self panGestureEnded:gesture];
- // break;
- // default:
- // break;
- // }
- //}
- //
- //- (void)panGestureBegan:(UIPanGestureRecognizer *)gesture {
- // _startContentOffset = self.contentOffset;
- // _startPanLocation = [gesture locationInView:self];
- // _isScrolling = NO;
- //
- // _lastContentOffset = self.contentOffset;
- // _isDragging = YES;
- // _isDecelerating = NO;
- //}
- //
- //- (void)panGestureChanged:(UIPanGestureRecognizer *)gesture {
- // CGPoint translation = [gesture translationInView:self];
- // CGPoint newContentOffset = CGPointMake(_startContentOffset.x, MAX(0, MIN(self.contentSize.height - CGRectGetHeight(self.bounds), _startContentOffset.y - translation.y)));
- // [self setContentOffset:newContentOffset animated:NO];
- //}
- //
- //- (void)panGestureEnded:(UIPanGestureRecognizer *)gesture {
- // CGPoint velocity = [gesture velocityInView:self];
- //
- // _isDragging = NO;
- // _isDecelerating = YES;
- //
- // _lastSpeed = velocity.y;
- // _lastUpdateTime = CACurrentMediaTime();
- // _scrollDuration = 0.1; // 设置滚动时长
- //
- // [self startScrollAnimation];
- //}
- //
- //- (void)startScrollAnimation {
- // if (_isScrolling) {
- // return;
- // }
- //
- // _isScrolling = YES;
- //
- // CADisplayLink *displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(scrollAnimation:)];
- // [displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
- //}
- //
- //- (void)scrollAnimation:(CADisplayLink *)displayLink {
- // NSTimeInterval currentTime = CACurrentMediaTime();
- // NSTimeInterval elapsedTime = currentTime - _lastUpdateTime;
- //
- // if (elapsedTime > _scrollDuration) {
- // elapsedTime = _scrollDuration;
- // }
- //
- // CGFloat deltaY = _lastSpeed * elapsedTime;
- //
- //// CGPoint contentOffset = CGPointMake(self.contentOffset.x, self.contentOffset.y - deltaY);
- //// [self setContentOffset:contentOffset animated:NO];
- //
- // CGPoint contentOffset = CGPointMake(self.contentOffset.x, MAX(0, MIN(self.contentSize.height - CGRectGetHeight(self.bounds), self.contentOffset.y - deltaY)));
- // [self setContentOffset:contentOffset animated:NO];
- //
- // _lastSpeed *= 0.9; // 减速系数
- //
- // if (fabs(_lastSpeed) < 10 || fabs(deltaY) < 1) {
- // [displayLink invalidate];
- // _isScrolling = NO;
- // }
- //
- // _lastUpdateTime = currentTime;
- //}
- // 禁用系统自带的上下滑动手势
- - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
- if (self.panBlock) {
- self.panBlock(YES);
- }
- return YES;
- }
- - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
- if (self.panBlock) {
- self.panBlock(YES);
- }
- return YES;
- }
- @end
|