MOMsgCustomTwoTableView.m 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. //
  2. // MOMsgCustomTwoTableView.m
  3. // MiMoLive
  4. //
  5. // Created by SuperC on 2024/3/28.
  6. //
  7. #import "MOMsgCustomTwoTableView.h"
  8. @interface MOMsgCustomTwoTableView ()<UIGestureRecognizerDelegate>
  9. @end
  10. @implementation MOMsgCustomTwoTableView
  11. {
  12. // UIPanGestureRecognizer *_panGesture;
  13. // CGPoint _startContentOffset;
  14. // CGPoint _startPanLocation;
  15. // NSTimeInterval _lastUpdateTime;
  16. // CGFloat _lastSpeed;
  17. // CGFloat _scrollDuration;
  18. // BOOL _isScrolling;
  19. //
  20. // CGPoint _lastContentOffset;
  21. // BOOL _isDragging;
  22. // BOOL _isDecelerating;
  23. }
  24. - (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style {
  25. self = [super initWithFrame:frame style:style];
  26. if (self) {
  27. // _panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGesture:)];
  28. // _panGesture.delegate = self;
  29. // [self addGestureRecognizer:_panGesture];
  30. }
  31. return self;
  32. }
  33. - (void)awakeFromNib{
  34. [super awakeFromNib];
  35. // _panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGesture:)];
  36. // _panGesture.delegate = self;
  37. // [self addGestureRecognizer:_panGesture];
  38. }
  39. //- (void)handlePanGesture:(UIPanGestureRecognizer *)gesture {
  40. // switch (gesture.state) {
  41. // case UIGestureRecognizerStateBegan:
  42. // [self panGestureBegan:gesture];
  43. // break;
  44. // case UIGestureRecognizerStateChanged:
  45. // [self panGestureChanged:gesture];
  46. // break;
  47. // case UIGestureRecognizerStateEnded:
  48. // case UIGestureRecognizerStateCancelled:
  49. // [self panGestureEnded:gesture];
  50. // break;
  51. // default:
  52. // break;
  53. // }
  54. //}
  55. //
  56. //- (void)panGestureBegan:(UIPanGestureRecognizer *)gesture {
  57. // _startContentOffset = self.contentOffset;
  58. // _startPanLocation = [gesture locationInView:self];
  59. // _isScrolling = NO;
  60. //
  61. // _lastContentOffset = self.contentOffset;
  62. // _isDragging = YES;
  63. // _isDecelerating = NO;
  64. //}
  65. //
  66. //- (void)panGestureChanged:(UIPanGestureRecognizer *)gesture {
  67. // CGPoint translation = [gesture translationInView:self];
  68. // CGPoint newContentOffset = CGPointMake(_startContentOffset.x, MAX(0, MIN(self.contentSize.height - CGRectGetHeight(self.bounds), _startContentOffset.y - translation.y)));
  69. // [self setContentOffset:newContentOffset animated:NO];
  70. //}
  71. //
  72. //- (void)panGestureEnded:(UIPanGestureRecognizer *)gesture {
  73. // CGPoint velocity = [gesture velocityInView:self];
  74. //
  75. // _isDragging = NO;
  76. // _isDecelerating = YES;
  77. //
  78. // _lastSpeed = velocity.y;
  79. // _lastUpdateTime = CACurrentMediaTime();
  80. // _scrollDuration = 0.1; // 设置滚动时长
  81. //
  82. // [self startScrollAnimation];
  83. //}
  84. //
  85. //- (void)startScrollAnimation {
  86. // if (_isScrolling) {
  87. // return;
  88. // }
  89. //
  90. // _isScrolling = YES;
  91. //
  92. // CADisplayLink *displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(scrollAnimation:)];
  93. // [displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
  94. //}
  95. //
  96. //- (void)scrollAnimation:(CADisplayLink *)displayLink {
  97. // NSTimeInterval currentTime = CACurrentMediaTime();
  98. // NSTimeInterval elapsedTime = currentTime - _lastUpdateTime;
  99. //
  100. // if (elapsedTime > _scrollDuration) {
  101. // elapsedTime = _scrollDuration;
  102. // }
  103. //
  104. // CGFloat deltaY = _lastSpeed * elapsedTime;
  105. //
  106. //// CGPoint contentOffset = CGPointMake(self.contentOffset.x, self.contentOffset.y - deltaY);
  107. //// [self setContentOffset:contentOffset animated:NO];
  108. //
  109. // CGPoint contentOffset = CGPointMake(self.contentOffset.x, MAX(0, MIN(self.contentSize.height - CGRectGetHeight(self.bounds), self.contentOffset.y - deltaY)));
  110. // [self setContentOffset:contentOffset animated:NO];
  111. //
  112. // _lastSpeed *= 0.9; // 减速系数
  113. //
  114. // if (fabs(_lastSpeed) < 10 || fabs(deltaY) < 1) {
  115. // [displayLink invalidate];
  116. // _isScrolling = NO;
  117. // }
  118. //
  119. // _lastUpdateTime = currentTime;
  120. //}
  121. // 禁用系统自带的上下滑动手势
  122. - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
  123. if (self.panBlock) {
  124. self.panBlock(YES);
  125. }
  126. return YES;
  127. }
  128. - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
  129. if (self.panBlock) {
  130. self.panBlock(YES);
  131. }
  132. return YES;
  133. }
  134. @end