// // MOMsgCustomTwoTableView.m // MiMoLive // // Created by SuperC on 2024/3/28. // #import "MOMsgCustomTwoTableView.h" @interface MOMsgCustomTwoTableView () @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