RQHomeSubPageVideoScrollCell.m 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. //
  2. // RQHomeSubPageVideoScrollCell.m
  3. // SDJK
  4. //
  5. // Created by 张嵘 on 2021/11/11.
  6. //
  7. #import "RQHomeSubPageVideoScrollCell.h"
  8. @interface RQHomeSubPageVideoScrollCell () <JXCategoryViewDelegate, JXPagerViewDelegate, JXPagerMainTableViewGestureDelegate>
  9. @property (nonatomic, readwrite, strong) RQHomeSubPageVideoScrollItemViewModel *viewModel;
  10. @property (weak, nonatomic) IBOutlet UIView *myContentView;
  11. @property (nonatomic, readwrite, strong) JXPagerView *pagerView;
  12. @property (nonatomic, readwrite, strong) JXCategoryTitleBackgroundView *categoryView;
  13. @property (nonatomic, readwrite, strong) NSArray <NSString *> *titles;
  14. @property (nonatomic, readonly, assign) float cellWeight;
  15. @end
  16. @implementation RQHomeSubPageVideoScrollCell
  17. #pragma mark - PublicMethods
  18. + (instancetype)cellWithCollectionView:(UICollectionView *)collectionView forIndexPath:(NSIndexPath *)indexPath {
  19. static NSString *ID = @"RQHomeSubPageVideoScrollCell";
  20. [collectionView registerNib:[UINib nibWithNibName:ID bundle:nil] forCellWithReuseIdentifier:ID];
  21. RQHomeSubPageVideoScrollCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath];
  22. if (!cell) cell = [self rq_viewFromXib];
  23. return cell;
  24. }
  25. - (void)bindViewModel:(RQHomeSubPageVideoScrollItemViewModel *)viewModel {
  26. _viewModel = viewModel;
  27. self.titles = [self.viewModel.childrenItemArr.rac_sequence map:^id _Nullable(ChildrenItem *childrenItem) {
  28. return [self lineFeedWithStr:childrenItem.typeName];
  29. }].array;
  30. [self.myContentView addSubview:self.pagerView];
  31. }
  32. #pragma mark - SystemMethods
  33. - (void)awakeFromNib {
  34. [super awakeFromNib];
  35. // Initialization code
  36. }
  37. - (void)layoutSubviews {
  38. [super layoutSubviews];
  39. self.pagerView.frame = CGRectMake(0, 0, RQ_SCREEN_WIDTH, RQ_FIT_HORIZONTAL(239.f));
  40. }
  41. #pragma mark - PrivateMethods
  42. - (NSString *)lineFeedWithStr:(NSString *)str {
  43. if (str.length > 8) {
  44. NSMutableString *strs = [[NSMutableString alloc] initWithString:str];
  45. [strs insertString:@"\n" atIndex:8];
  46. return strs.copy;
  47. } else {
  48. return str;
  49. }
  50. }
  51. #pragma mark - JXPagerViewDelegate
  52. - (UIView *)tableHeaderViewInPagerView:(JXPagerView *)pagerView {
  53. return UIView.new;
  54. }
  55. - (NSUInteger)tableHeaderViewHeightInPagerView:(JXPagerView *)pagerView {
  56. return 0.f;
  57. }
  58. - (NSUInteger)heightForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
  59. return self.titles.count > 1? self.cellWeight * ((37.f + (4.3f * 2)) / 65.f) : 0;
  60. }
  61. - (UIView *)viewForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
  62. return self.categoryView;
  63. }
  64. - (NSInteger)numberOfListsInPagerView:(JXPagerView *)pagerView {
  65. //和categoryView的item数量一致
  66. return self.categoryView.titles.count;
  67. }
  68. - (id<JXPagerViewListViewDelegate>)pagerView:(JXPagerView *)pagerView initListAtIndex:(NSInteger)index {
  69. // ChildrenItem *childrenItem = (self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectTwo || self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectThree)? self.viewModel.treeListModel.children.lastObject : self.viewModel.treeListModel.children[index];
  70. // RQVideoDetailSubPageViewModel *videoDetailSubPageViewModel = [[RQVideoDetailSubPageViewModel alloc] initWithServices:self.viewModel.services params:@{
  71. // RQViewModelTitleKey : childrenItem.typeName,
  72. // RQViewModelIDKey : childrenItem.typeDescribe? : @"",
  73. // RQViewModelUtilKey : childrenItem.videos,
  74. // RQViewCommonValueKey: self.viewModel.indexPath,
  75. // }];
  76. // RQVideoDetailSubPageViewController *videoDetailSubPageViewController = [[RQVideoDetailSubPageViewController alloc] initWithViewModel:videoDetailSubPageViewModel];
  77. ChildrenItem *childrenItem = _viewModel.childrenItemArr[index];
  78. RQHomeSubPageVideoScrollViewModel *homeSubPageVideoScrollViewModel = [[RQHomeSubPageVideoScrollViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:@{
  79. RQViewModelUtilKey : self.viewModel.treeListModel,
  80. RQVideoItemIndexKey : @(index),
  81. RQVideoItemIndexPathKey : [NSIndexPath indexPathForRow:index inSection:self.viewModel.section],
  82. RQHomePageSubjectTypeKey : @(self.viewModel.homePageSubjectType),
  83. RQViewCommonValueKey : childrenItem.videos,
  84. }];
  85. RQHomeSubPageVideoScrollViewController *homeSubPageVideoScrollViewController = [[RQHomeSubPageVideoScrollViewController alloc] initWithViewModel:homeSubPageVideoScrollViewModel];
  86. homeSubPageVideoScrollViewController.superCollectionView = self.superCollectionView;
  87. homeSubPageVideoScrollViewController.view.frame = self.frame;
  88. return homeSubPageVideoScrollViewController;
  89. }
  90. #pragma mark - JXCategoryViewDelegate
  91. - (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
  92. }
  93. - (void)categoryView:(JXCategoryBaseView *)categoryView didClickSelectedItemAtIndex:(NSInteger)index {
  94. // ChildrenItem *childrenItem = (self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectTwo || self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectThree)? self.viewModel.treeListModel.children.lastObject : self.viewModel.treeListModel.children[index];
  95. // [RQNotificationCenter postNotificationName:RQPlayVideoUrlNotification object:@{
  96. // RQPlayVideoItemKey : childrenItem.videos.firstObject,
  97. // RQPlayVideoItemArrKey : childrenItem.videos,
  98. // }];
  99. }
  100. - (void)categoryView:(JXCategoryBaseView *)categoryView didScrollSelectedItemAtIndex:(NSInteger)index {
  101. // ChildrenItem *childrenItem = (self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectTwo || self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectThree)? self.viewModel.treeListModel.children.lastObject : self.viewModel.treeListModel.children[index];
  102. // [RQNotificationCenter postNotificationName:RQPlayVideoUrlNotification object:@{
  103. // RQPlayVideoItemKey : childrenItem.videos.firstObject,
  104. // RQPlayVideoItemArrKey : childrenItem.videos,
  105. // }];
  106. }
  107. #pragma mark - JXPagerMainTableViewGestureDelegate
  108. - (BOOL)mainTableViewGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
  109. if ([self checkIsNestContentScrollView:(UIScrollView *)gestureRecognizer.view] || [self checkIsNestContentScrollView:(UIScrollView *)otherGestureRecognizer.view]) {
  110. //如果交互的是嵌套的contentScrollView,证明在左右滑动,就不允许同时响应
  111. return NO;
  112. }
  113. return [gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]];
  114. }
  115. - (BOOL)checkIsNestContentScrollView:(UIScrollView *)scrollView {
  116. for (RQHomeSubPageVideoScrollViewController *list in self.pagerView.validListDict.allValues) {
  117. if (list.contentScrollView == scrollView) {
  118. return YES;
  119. }
  120. }
  121. return NO;
  122. }
  123. #pragma mark - LazyLoad
  124. - (JXPagerView *)pagerView {
  125. if (!_pagerView) {
  126. _pagerView = [[JXPagerView alloc] initWithDelegate:self];
  127. _pagerView.mainTableView.gestureDelegate = self;
  128. _pagerView.mainTableView.bounces = NO;
  129. // _pagerView.pinSectionHeaderVerticalOffset = self.cycleScrollViewHeight;
  130. _pagerView.isMirror = YES;
  131. }
  132. return _pagerView;
  133. }
  134. - (JXCategoryTitleBackgroundView *)categoryView {
  135. if (!_categoryView) {
  136. _categoryView = [[JXCategoryTitleBackgroundView alloc] init];
  137. _categoryView.delegate = self;
  138. _categoryView.titles = self.titles;
  139. _categoryView.titleSelectedColor = UIColor.whiteColor;
  140. _categoryView.titleColor = UIColor.whiteColor;
  141. _categoryView.titleFont = RQMediumFont(11);
  142. _categoryView.titleNumberOfLines = 0;
  143. _categoryView.titleSelectedFont = RQMediumFont(11);
  144. _categoryView.titleColorGradientEnabled = YES;
  145. _categoryView.contentEdgeInsetLeft = 3;
  146. _categoryView.contentEdgeInsetRight = 3;
  147. _categoryView.cellWidth = self.cellWeight;
  148. _categoryView.cellSpacing = 3;
  149. _categoryView.backgroundColor = RQ_MAIN_TEXT_COLOR_1;
  150. _categoryView.normalBackgroundColor = RQ_MAIN_TEXT_COLOR_3;
  151. _categoryView.backgroundHeight = self.cellWeight * (37.f / 65.f);
  152. _categoryView.borderLineWidth = 0;
  153. JXCategoryIndicatorImageView *indicatorImageView1 = [[JXCategoryIndicatorImageView alloc] init];
  154. indicatorImageView1.componentPosition = JXCategoryComponentPosition_Top;
  155. indicatorImageView1.indicatorImageView.image = RQImageNamed(@"arrowUP");
  156. indicatorImageView1.indicatorImageViewSize = CGSizeMake(self.cellWeight * (11 / 65.f), self.cellWeight * (11 / 65.f) * (4.3f / 11.f));
  157. _categoryView.indicators = @[indicatorImageView1];
  158. _categoryView.defaultSelectedIndex = 0;
  159. /// !!!: 将列表容器视图关联到 categoryView
  160. _categoryView.listContainer = (id<JXCategoryViewListContainer>)self.pagerView.listContainerView;
  161. }
  162. return _categoryView;
  163. }
  164. - (NSArray<NSString *> *)titles {
  165. if (!_titles) {
  166. _titles = @[@"侧方停车", @"倒车入库", @"坡道定点\n停车与起步", @"曲线行驶", @"直角转弯"];
  167. }
  168. return _titles;
  169. }
  170. - (float)cellWeight {
  171. return (RQ_SCREEN_WIDTH - (3 * 6)) / 5.f;
  172. }
  173. @end