RQHomeSubPageVideoScrollViewController.m 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. //
  2. // RQHomeSubPageVideoScrollViewController.m
  3. // JSJP
  4. //
  5. // Created by 张嵘 on 2021/11/11.
  6. //
  7. #import "RQHomeSubPageVideoScrollViewController.h"
  8. @interface RQHomeSubPageVideoScrollViewController ()
  9. /// viewModel
  10. @property (nonatomic, readonly, strong) RQHomeSubPageVideoScrollViewModel *viewModel;
  11. @property (nonatomic, readwrite, strong) JXPagerView *pagerView;
  12. @property (nonatomic, readwrite, strong) JXCategoryTitleView *categoryView;
  13. @property (nonatomic, readwrite, strong) NSArray <NSString *> *titles;
  14. @property (nonatomic, readwrite, strong) UIScrollView *currentListView;
  15. @property (nonatomic, readwrite, copy) void(^scrollCallback)(UIScrollView *scrollView);
  16. @end
  17. @implementation RQHomeSubPageVideoScrollViewController
  18. @dynamic viewModel;
  19. #pragma mark - SystemMethod
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. /// 初始化
  23. [self rq_setup];
  24. }
  25. - (void)viewDidLayoutSubviews {
  26. [super viewDidLayoutSubviews];
  27. self.pagerView.frame = CGRectMake(0, 0, RQ_SCREEN_WIDTH, RQ_FIT_HORIZONTAL(194.f));
  28. }
  29. #pragma mark - PrivateMethods
  30. /// 初始化
  31. - (void)rq_setup {
  32. /// set up ...
  33. self.titles = [self.viewModel.videosItemArr.rac_sequence map:^id _Nullable(VideosItem *videosItem) {
  34. return videosItem.title;
  35. }].array;
  36. if (self.titles.count > 1) {
  37. self.titles = @[self.titles.firstObject];
  38. }
  39. [self.view addSubview:self.pagerView];
  40. }
  41. #pragma mark - JXPagerViewDelegate
  42. - (UIView *)tableHeaderViewInPagerView:(JXPagerView *)pagerView {
  43. return [UIView new];
  44. }
  45. - (NSUInteger)tableHeaderViewHeightInPagerView:(JXPagerView *)pagerView {
  46. return 0.f;
  47. }
  48. - (NSUInteger)heightForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
  49. return 0.f;
  50. }
  51. - (UIView *)viewForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
  52. return self.categoryView;
  53. }
  54. - (NSInteger)numberOfListsInPagerView:(JXPagerView *)pagerView {
  55. //和categoryView的item数量一致
  56. return self.categoryView.titles.count;
  57. }
  58. - (id<JXPagerViewListViewDelegate>)pagerView:(JXPagerView *)pagerView initListAtIndex:(NSInteger)index {
  59. @weakify(self);
  60. RQHomeSubPageVideoScrollSubViewModel *homeSubPageVideoScrollSubViewModel = [[RQHomeSubPageVideoScrollSubViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:@{
  61. RQViewModelUtilKey : self.viewModel.treeListModel,
  62. RQVideoItemIndexKey : @(self.viewModel.index),
  63. RQVideoItemIndexPathKey : [NSIndexPath indexPathForRow:index inSection:self.viewModel.myIndexPath.section],
  64. RQHomePageSubjectTypeKey : @(self.viewModel.homePageSubjectType),
  65. RQViewCommonValueKey : self.viewModel.videosItemArr[index],
  66. }];
  67. RQHomeSubPageVideoScrollSubViewController *homeSubPageVideoScrollSubViewController = [[RQHomeSubPageVideoScrollSubViewController alloc] initWithViewModel:homeSubPageVideoScrollSubViewModel];
  68. homeSubPageVideoScrollSubViewController.scrollCallback = ^(UIScrollView *scrollView) {
  69. @strongify(self);
  70. self.scrollCallback(scrollView);
  71. };
  72. self.currentListView = homeSubPageVideoScrollSubViewController.tableView;
  73. return homeSubPageVideoScrollSubViewController;
  74. }
  75. - (void)pagerView:(JXPagerView *)pagerView mainTableViewDidScroll:(UIScrollView *)scrollView {
  76. }
  77. #pragma mark - JXCategoryViewDelegate
  78. - (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
  79. self.navigationController.interactivePopGestureRecognizer.enabled = (index == 0);
  80. //根据选中的下标,实时更新currentListView
  81. RQHomeSubPageVideoScrollSubViewController *list = (RQHomeSubPageVideoScrollSubViewController *)self.pagerView.listContainerView.validListDict[@(index)];
  82. self.currentListView = list.tableView;
  83. }
  84. - (void)categoryView:(JXCategoryBaseView *)categoryView didClickSelectedItemAtIndex:(NSInteger)index {
  85. }
  86. - (void)categoryView:(JXCategoryBaseView *)categoryView didScrollSelectedItemAtIndex:(NSInteger)index {
  87. }
  88. #pragma mark - JXPagerMainTableViewGestureDelegate
  89. - (BOOL)mainTableViewGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
  90. //禁止categoryView左右滑动的时候,上下和左右都可以滚动
  91. if (otherGestureRecognizer == self.categoryView.collectionView.panGestureRecognizer) {
  92. return NO;
  93. }
  94. return [gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]];
  95. }
  96. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  97. !self.scrollCallback ?: self.scrollCallback(scrollView);
  98. }
  99. #pragma mark - JXPagingViewListViewDelegate
  100. - (UIView *)listView {
  101. return self.view;
  102. }
  103. - (UIScrollView *)listScrollView {
  104. return self.currentListView;
  105. }
  106. - (void)listViewDidScrollCallback:(void (^)(UIScrollView *))callback {
  107. self.scrollCallback = callback;
  108. }
  109. - (void)listScrollViewWillResetContentOffset {
  110. //当前的listScrollView需要重置的时候,就把所有列表的contentOffset都重置了
  111. // for (RQHomePageSubjectOneOrFourViewController *list in self.pagerView.listContainerView.validListDict.allValues) {
  112. // list.collectionView.contentOffset = CGPointZero;
  113. // }
  114. }
  115. #pragma mark - LazyLoad
  116. - (JXPagerView *)pagerView {
  117. if (!_pagerView) {
  118. _pagerView = [[JXPagerView alloc] initWithDelegate:self];
  119. _pagerView.mainTableView.gestureDelegate = self;
  120. _pagerView.mainTableView.bounces = NO;
  121. _pagerView.listContainerView.categoryNestPagingEnabled = YES;
  122. _pagerView.listContainerView.frame = CGRectMake(0, RQHeightForPinSectionHeaderInPagerView, RQ_SCREEN_WIDTH, RQ_SCREEN_HEIGHT - (RQ_APPLICATION_NAV_BAR_HEIGHT + RQ_APPLICATION_STATUS_BAR_HEIGHT) - RQHeightForPinSectionHeaderInPagerView_One - RQHeightForPinSectionHeaderInPagerView - RQ_APPLICATION_TAB_BAR_HEIGHT - RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT);
  123. self.contentScrollView = _pagerView.listContainerView.contentScrollView;
  124. }
  125. return _pagerView;
  126. }
  127. - (JXCategoryTitleView *)categoryView {
  128. if (!_categoryView) {
  129. _categoryView = [[JXCategoryTitleView alloc] init];
  130. _categoryView.titles = self.titles;
  131. _categoryView.backgroundColor = [UIColor whiteColor];
  132. _categoryView.titleSelectedColor = RQ_MAIN_TEXT_COLOR_1;
  133. _categoryView.titleColor = RQ_MAIN_TEXT_COLOR_2;
  134. _categoryView.titleFont = RQRegularFont(13);
  135. _categoryView.titleSelectedFont = RQRegularFont(15);
  136. _categoryView.titleColorGradientEnabled = YES;
  137. _categoryView.titleLabelZoomEnabled = NO;
  138. _categoryView.contentScrollViewClickTransitionAnimationEnabled = NO;
  139. _categoryView.titleLabelZoomSelectedVerticalOffset = 0.0f;
  140. _categoryView.titleLabelVerticalOffset = 6.f;
  141. JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc] init];
  142. lineView.indicatorColor = RQ_MAIN_COLOR;
  143. lineView.indicatorWidth = 20;
  144. lineView.indicatorHeight = 4;
  145. _categoryView.indicators = @[lineView];
  146. _categoryView.defaultSelectedIndex = 0;
  147. _categoryView.listContainer = (id<JXCategoryViewListContainer>)self.pagerView.listContainerView;
  148. _categoryView.delegate = self;
  149. }
  150. return _categoryView;
  151. }
  152. - (NSArray<NSString *> *)titles {
  153. if (!_titles) {
  154. _titles = @[@"侧方停车", @"倒车入库", @"坡道定点\n停车与起步", @"曲线行驶", @"直角转弯"];
  155. }
  156. return _titles;
  157. }
  158. @end