JXPagerListRefreshView.m 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. //
  2. // JXPagerListRefreshView.m
  3. // JXPagerView
  4. //
  5. // Created by jiaxin on 2018/8/28.
  6. // Copyright © 2018年 jiaxin. All rights reserved.
  7. //
  8. #import "JXPagerListRefreshView.h"
  9. @interface JXPagerListRefreshView()
  10. @property (nonatomic, assign) CGFloat lastScrollingListViewContentOffsetY;
  11. @end
  12. @implementation JXPagerListRefreshView
  13. - (instancetype)initWithDelegate:(id<JXPagerViewDelegate>)delegate listContainerType:(JXPagerListContainerType)type {
  14. self = [super initWithDelegate:delegate listContainerType:type];
  15. if (self) {
  16. self.mainTableView.bounces = NO;
  17. }
  18. return self;
  19. }
  20. - (void)preferredProcessListViewDidScroll:(UIScrollView *)scrollView {
  21. BOOL shouldProcess = YES;
  22. if (self.currentScrollingListView.contentOffset.y > self.lastScrollingListViewContentOffsetY) {
  23. //往上滚动
  24. }else {
  25. //往下滚动
  26. if (self.mainTableView.contentOffset.y == 0) {
  27. shouldProcess = NO;
  28. }else {
  29. if (self.mainTableView.contentOffset.y < self.mainTableViewMaxContentOffsetY) {
  30. //mainTableView的header还没有消失,让listScrollView一直为0
  31. if (self.currentList && [self.currentList respondsToSelector:@selector(listScrollViewWillResetContentOffset)]) {
  32. [self.currentList listScrollViewWillResetContentOffset];
  33. }
  34. [self setListScrollViewToMinContentOffsetY:self.currentScrollingListView];
  35. if (self.automaticallyDisplayListVerticalScrollIndicator) {
  36. self.currentScrollingListView.showsVerticalScrollIndicator = NO;
  37. }
  38. }
  39. }
  40. }
  41. if (shouldProcess) {
  42. if (self.mainTableView.contentOffset.y < self.mainTableViewMaxContentOffsetY) {
  43. //处于下拉刷新的状态,scrollView.contentOffset.y为负数,就重置为0
  44. if (self.currentScrollingListView.contentOffset.y > [self minContentOffsetYInListScrollView:self.currentScrollingListView]) {
  45. //mainTableView的header还没有消失,让listScrollView一直为0
  46. if (self.currentList && [self.currentList respondsToSelector:@selector(listScrollViewWillResetContentOffset)]) {
  47. [self.currentList listScrollViewWillResetContentOffset];
  48. }
  49. [self setListScrollViewToMinContentOffsetY:self.currentScrollingListView];
  50. if (self.automaticallyDisplayListVerticalScrollIndicator) {
  51. self.currentScrollingListView.showsVerticalScrollIndicator = NO;
  52. }
  53. }
  54. } else {
  55. //mainTableView的header刚好消失,固定mainTableView的位置,显示listScrollView的滚动条
  56. self.mainTableView.contentOffset = CGPointMake(0, self.mainTableViewMaxContentOffsetY);
  57. if (self.automaticallyDisplayListVerticalScrollIndicator) {
  58. self.currentScrollingListView.showsVerticalScrollIndicator = YES;
  59. }
  60. }
  61. }
  62. self.lastScrollingListViewContentOffsetY = self.currentScrollingListView.contentOffset.y;
  63. }
  64. - (void)preferredProcessMainTableViewDidScroll:(UIScrollView *)scrollView {
  65. if (self.pinSectionHeaderVerticalOffset != 0) {
  66. if (!(self.currentScrollingListView != nil && self.currentScrollingListView.contentOffset.y > [self minContentOffsetYInListScrollView:self.currentScrollingListView])) {
  67. //没有处于滚动某一个listView的状态
  68. if (scrollView.contentOffset.y <= 0) {
  69. self.mainTableView.bounces = NO;
  70. self.mainTableView.contentOffset = CGPointZero;
  71. return;
  72. }else {
  73. self.mainTableView.bounces = YES;
  74. }
  75. }
  76. }
  77. if (self.currentScrollingListView != nil && self.currentScrollingListView.contentOffset.y > [self minContentOffsetYInListScrollView:self.currentScrollingListView]) {
  78. //mainTableView的header已经滚动不见,开始滚动某一个listView,那么固定mainTableView的contentOffset,让其不动
  79. [self setMainTableViewToMaxContentOffsetY];
  80. }
  81. if (scrollView.contentOffset.y < self.mainTableViewMaxContentOffsetY) {
  82. //mainTableView已经显示了header,listView的contentOffset需要重置
  83. for (id<JXPagerViewListViewDelegate> list in self.validListDict.allValues) {
  84. //正在下拉刷新时,不需要重置
  85. UIScrollView *listScrollView = [list listScrollView];
  86. if (listScrollView.contentOffset.y > 0) {
  87. if ([list respondsToSelector:@selector(listScrollViewWillResetContentOffset)]) {
  88. [list listScrollViewWillResetContentOffset];
  89. }
  90. [self setListScrollViewToMinContentOffsetY:listScrollView];
  91. }
  92. }
  93. }
  94. if (scrollView.contentOffset.y > self.mainTableViewMaxContentOffsetY && self.currentScrollingListView.contentOffset.y == [self minContentOffsetYInListScrollView:self.currentScrollingListView]) {
  95. //当往上滚动mainTableView的headerView时,滚动到底时,修复listView往上小幅度滚动
  96. [self setMainTableViewToMaxContentOffsetY];
  97. }
  98. }
  99. @end