RQHomeSubPageVideoScrollCell.m 9.6 KB

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