RQHomeSubPageViewController.m 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. //
  2. // RQHomeSubPageViewController.m
  3. // XinShouJiaDao
  4. //
  5. // Created by 张嵘 on 2021/7/8.
  6. // Copyright © 2021 JCZ. All rights reserved.
  7. //
  8. #import "RQHomeSubPageViewController.h"
  9. @interface RQHomeSubPageViewController ()
  10. /// viewModel
  11. @property (nonatomic, readonly, strong) RQHomeSubPageViewModel *viewModel;
  12. @property (nonatomic, readwrite, strong) JXPagerView *pagerView;
  13. @property (nonatomic, readwrite, strong) JXCategoryTitleView *categoryView;
  14. @property (nonatomic, readwrite, strong) NSArray <NSString *> *titles;
  15. @property (nonatomic, readwrite, strong) UIScrollView *currentListView;
  16. @property (nonatomic, readwrite, copy) void(^scrollCallback)(UIScrollView *scrollView);
  17. @end
  18. @implementation RQHomeSubPageViewController
  19. @dynamic viewModel;
  20. #pragma mark - SystemMethod
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. /// 初始化
  24. [self rq_setup];
  25. }
  26. - (void)viewDidLayoutSubviews {
  27. [super viewDidLayoutSubviews];
  28. self.pagerView.frame = CGRectMake(0, 0, RQ_SCREEN_WIDTH, RQ_SCREEN_HEIGHT - RQ_APPLICATION_TOP_BAR_HEIGHT - RQHeightForPinSectionHeaderInPagerView_One - RQ_APPLICATION_TAB_BAR_HEIGHT - RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT);
  29. }
  30. #pragma mark - PrivateMethods
  31. /// 初始化
  32. - (void)rq_setup {
  33. /// set up ...
  34. [self.view addSubview:self.pagerView];
  35. }
  36. #pragma mark - JXPagerViewDelegate
  37. - (UIView *)tableHeaderViewInPagerView:(JXPagerView *)pagerView {
  38. return [UIView new];
  39. }
  40. - (NSUInteger)tableHeaderViewHeightInPagerView:(JXPagerView *)pagerView {
  41. return 0.f;
  42. }
  43. - (NSUInteger)heightForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
  44. return RQHeightForPinSectionHeaderInPagerView;
  45. }
  46. - (UIView *)viewForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
  47. return self.categoryView;
  48. }
  49. - (NSInteger)numberOfListsInPagerView:(JXPagerView *)pagerView {
  50. //和categoryView的item数量一致
  51. return self.categoryView.titles.count;
  52. }
  53. - (id<JXPagerViewListViewDelegate>)pagerView:(JXPagerView *)pagerView initListAtIndex:(NSInteger)index {
  54. @weakify(self);
  55. // switch (index) {
  56. // case 0: {
  57. // RQHomePageSubjectOneOrFourViewModel *homePageSubjectOneViewModel = [[RQHomePageSubjectOneOrFourViewModel alloc] initWithServices:self.viewModel.services params:@{RQHomePageCarTypeKey : @(self.viewModel.homePageCarType), RQHomePageSubjectTypeKey : @(index)}];
  58. // RQHomePageSubjectOneOrFourViewController *homePageSubjectOneViewController = [[RQHomePageSubjectOneOrFourViewController alloc] initWithViewModel:homePageSubjectOneViewModel];
  59. // homePageSubjectOneViewController.scrollCallback = ^(UIScrollView *scrollView) {
  60. // @strongify(self);
  61. // self.scrollCallback(scrollView);
  62. // };
  63. // self.currentListView = homePageSubjectOneViewController.collectionView;
  64. // return homePageSubjectOneViewController;
  65. // }
  66. // case 3: {
  67. // RQHomePageSubjectOneOrFourViewModel *homePageSubjectFourViewModel = [[RQHomePageSubjectOneOrFourViewModel alloc] initWithServices:self.viewModel.services params:@{RQHomePageCarTypeKey : @(self.viewModel.homePageCarType), RQHomePageSubjectTypeKey : @(index)}];
  68. // RQHomePageSubjectOneOrFourViewController *homePageSubjectFourViewController = [[RQHomePageSubjectOneOrFourViewController alloc] initWithViewModel:homePageSubjectFourViewModel];
  69. // homePageSubjectFourViewController.scrollCallback = ^(UIScrollView *scrollView) {
  70. // @strongify(self);
  71. // self.scrollCallback(scrollView);
  72. // };
  73. // self.currentListView = homePageSubjectFourViewController.collectionView;
  74. // return homePageSubjectFourViewController;
  75. // }
  76. //
  77. // default:
  78. // return nil;
  79. // }
  80. RQHomePageSubjectOneOrFourViewModel *homePageSubjectFourViewModel = [[RQHomePageSubjectOneOrFourViewModel alloc] initWithServices:self.viewModel.services params:@{RQHomePageCarTypeKey : @(self.viewModel.homePageCarType), RQHomePageSubjectTypeKey : @(index)}];
  81. RQHomePageSubjectOneOrFourViewController *homePageSubjectFourViewController = [[RQHomePageSubjectOneOrFourViewController alloc] initWithViewModel:homePageSubjectFourViewModel];
  82. homePageSubjectFourViewController.scrollCallback = ^(UIScrollView *scrollView) {
  83. @strongify(self);
  84. self.scrollCallback(scrollView);
  85. };
  86. self.currentListView = homePageSubjectFourViewController.collectionView;
  87. return homePageSubjectFourViewController;
  88. }
  89. - (void)pagerView:(JXPagerView *)pagerView mainTableViewDidScroll:(UIScrollView *)scrollView {
  90. }
  91. #pragma mark - JXCategoryViewDelegate
  92. - (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
  93. self.navigationController.interactivePopGestureRecognizer.enabled = (index == 0);
  94. //根据选中的下标,实时更新currentListView
  95. RQHomePageSubjectOneOrFourViewController *list = (RQHomePageSubjectOneOrFourViewController *)self.pagerView.listContainerView.validListDict[@(index)];
  96. self.currentListView = list.collectionView;
  97. RQ_COMMON_MANAGER.subject = index;
  98. }
  99. - (void)categoryView:(JXCategoryBaseView *)categoryView didClickSelectedItemAtIndex:(NSInteger)index {
  100. }
  101. - (void)categoryView:(JXCategoryBaseView *)categoryView didScrollSelectedItemAtIndex:(NSInteger)index {
  102. }
  103. #pragma mark - JXPagerMainTableViewGestureDelegate
  104. - (BOOL)mainTableViewGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
  105. //禁止categoryView左右滑动的时候,上下和左右都可以滚动
  106. // NSLog(@"%@--------%@",NSStringFromClass([gestureRecognizer.view class]),NSStringFromClass([otherGestureRecognizer.view class]));
  107. if (otherGestureRecognizer == self.categoryView.collectionView.panGestureRecognizer) {
  108. return NO;
  109. }
  110. return [gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]];
  111. }
  112. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  113. !self.scrollCallback ?: self.scrollCallback(scrollView);
  114. }
  115. #pragma mark - JXPagingViewListViewDelegate
  116. - (UIView *)listView {
  117. return self.view;
  118. }
  119. - (UIScrollView *)listScrollView {
  120. return self.tableView;
  121. }
  122. - (void)listViewDidScrollCallback:(void (^)(UIScrollView *))callback {
  123. self.scrollCallback = callback;
  124. }
  125. //- (void)listWillAppear {
  126. // NSLog(@"%@:%@", self.title, NSStringFromSelector(_cmd));
  127. //}
  128. //
  129. //- (void)listDidAppear {
  130. // NSLog(@"%@:%@", self.title, NSStringFromSelector(_cmd));
  131. //}
  132. //
  133. //- (void)listWillDisappear {
  134. // NSLog(@"%@:%@", self.title, NSStringFromSelector(_cmd));
  135. //}
  136. //
  137. //- (void)listDidDisappear {
  138. // NSLog(@"%@:%@", self.title, NSStringFromSelector(_cmd));
  139. //}
  140. - (void)listScrollViewWillResetContentOffset {
  141. //当前的listScrollView需要重置的时候,就把所有列表的contentOffset都重置了
  142. // for (RQHomePageSubjectOneOrFourViewController *list in self.pagerView.listContainerView.validListDict.allValues) {
  143. // list.collectionView.contentOffset = CGPointZero;
  144. // }
  145. }
  146. #pragma mark - LazyLoad
  147. - (JXPagerView *)pagerView {
  148. if (!_pagerView) {
  149. _pagerView = [[JXPagerView alloc] initWithDelegate:self];
  150. _pagerView.mainTableView.gestureDelegate = self;
  151. _pagerView.mainTableView.bounces = NO;
  152. _pagerView.listContainerView.categoryNestPagingEnabled = YES;
  153. _pagerView.listContainerView.frame = CGRectMake(0, RQHeightForPinSectionHeaderInPagerView, RQ_SCREEN_WIDTH, RQ_SCREEN_HEIGHT - RQ_APPLICATION_TOP_BAR_HEIGHT - RQHeightForPinSectionHeaderInPagerView_One - RQHeightForPinSectionHeaderInPagerView - RQ_APPLICATION_TAB_BAR_HEIGHT - RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT);
  154. self.contentScrollView = _pagerView.listContainerView.contentScrollView;
  155. }
  156. return _pagerView;
  157. }
  158. - (JXCategoryTitleView *)categoryView {
  159. if (!_categoryView) {
  160. _categoryView = [[JXCategoryTitleView alloc] init];
  161. _categoryView.titles = self.titles;
  162. _categoryView.backgroundColor = [UIColor whiteColor];
  163. _categoryView.titleSelectedColor = RQ_MAIN_TEXT_COLOR_1;
  164. _categoryView.titleColor = RQ_MAIN_TEXT_COLOR_2;
  165. _categoryView.titleFont = RQRegularFont(16);
  166. _categoryView.titleSelectedFont = RQRegularFont(18);
  167. _categoryView.titleColorGradientEnabled = YES;
  168. _categoryView.titleLabelZoomEnabled = NO;
  169. _categoryView.contentScrollViewClickTransitionAnimationEnabled = NO;
  170. _categoryView.titleLabelZoomSelectedVerticalOffset = 0.0f;
  171. _categoryView.titleLabelVerticalOffset = 6.f;
  172. _categoryView.cellWidth = (RQ_SCREEN_WIDTH - 32.f) / self.titles.count;
  173. _categoryView.cellSpacing = 0;
  174. JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc] init];
  175. lineView.indicatorColor = RQ_MAIN_COLOR;
  176. lineView.indicatorWidth = 20;
  177. lineView.indicatorHeight = 4;
  178. _categoryView.indicators = @[lineView];
  179. _categoryView.defaultSelectedIndex = 0;
  180. _categoryView.listContainer = (id<JXCategoryViewListContainer>)self.pagerView.listContainerView;
  181. _categoryView.delegate = self;
  182. }
  183. return _categoryView;
  184. }
  185. - (NSArray<NSString *> *)titles {
  186. return @[@"科目一", @"科目二", @"科目三", @"科目四"];
  187. }
  188. @end