123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- //
- // RQHomeSubPageVideoScrollCell.m
- // JSJP
- //
- // Created by 张嵘 on 2021/11/11.
- //
- #import "RQHomeSubPageVideoScrollCell.h"
- @interface RQHomeSubPageVideoScrollCell () <JXCategoryViewDelegate, JXPagerViewDelegate, JXPagerMainTableViewGestureDelegate>
- @property (nonatomic, readwrite, strong) RQHomeSubPageVideoScrollItemViewModel *viewModel;
- @property (weak, nonatomic) IBOutlet UIView *myContentView;
- @property (nonatomic, readwrite, strong) JXPagerView *pagerView;
- @property (nonatomic, readwrite, strong) JXCategoryTitleBackgroundView *categoryView;
- @property (nonatomic, readwrite, strong) NSArray <NSString *> *titles;
- @property (nonatomic, readonly, assign) float cellWeight;
- @property (weak, nonatomic) IBOutlet UILabel *myTitleLabel;
- @end
- @implementation RQHomeSubPageVideoScrollCell
- #pragma mark - PublicMethods
- + (instancetype)cellWithCollectionView:(UICollectionView *)collectionView forIndexPath:(NSIndexPath *)indexPath {
- static NSString *ID = @"RQHomeSubPageVideoScrollCell";
- [collectionView registerNib:[UINib nibWithNibName:ID bundle:nil] forCellWithReuseIdentifier:ID];
- RQHomeSubPageVideoScrollCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath];
- if (!cell) cell = [self rq_viewFromXib];
- return cell;
- }
- - (void)bindViewModel:(RQHomeSubPageVideoScrollItemViewModel *)viewModel {
- _viewModel = viewModel;
- _myTitleLabel.text = (self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectTwo)? @"科目二考试项目讲解" : @"科目三考试项目讲解";
- self.titles = [self.viewModel.childrenItemArr.rac_sequence map:^id _Nullable(ChildrenItem *childrenItem) {
- return [self lineFeedWithStr:childrenItem.typeName];
- }].array;
- [self.myContentView addSubview:self.pagerView];
- }
- #pragma mark - SystemMethods
- - (void)awakeFromNib {
- [super awakeFromNib];
- // Initialization code
- }
- - (void)layoutSubviews {
- [super layoutSubviews];
- self.pagerView.frame = CGRectMake(16, 56, RQ_SCREEN_WIDTH - 16 - 16, RQ_FIT_HORIZONTAL(240.f));
- }
- #pragma mark - PrivateMethods
- - (NSString *)lineFeedWithStr:(NSString *)str {
- if (str.length > 8) {
- NSMutableString *strs = [[NSMutableString alloc] initWithString:str];
- [strs insertString:@"\n" atIndex:8];
- return strs.copy;
- } else {
- return str;
- }
- }
- #pragma mark - JXPagerViewDelegate
- - (UIView *)tableHeaderViewInPagerView:(JXPagerView *)pagerView {
- return UIView.new;
- }
- - (NSUInteger)tableHeaderViewHeightInPagerView:(JXPagerView *)pagerView {
- return 0.f;
- }
- - (NSUInteger)heightForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
- return self.titles.count > 1? self.cellWeight * ((37.f + (4.3f * 2)) / 65.f) : 0;
- }
- - (UIView *)viewForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
- return self.categoryView;
- }
- - (NSInteger)numberOfListsInPagerView:(JXPagerView *)pagerView {
- //和categoryView的item数量一致
- return self.categoryView.titles.count;
- }
- - (id<JXPagerViewListViewDelegate>)pagerView:(JXPagerView *)pagerView initListAtIndex:(NSInteger)index {
- // ChildrenItem *childrenItem = (self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectTwo || self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectThree)? self.viewModel.treeListModel.children.lastObject : self.viewModel.treeListModel.children[index];
- // RQVideoDetailSubPageViewModel *videoDetailSubPageViewModel = [[RQVideoDetailSubPageViewModel alloc] initWithServices:self.viewModel.services params:@{
- // RQViewModelTitleKey : childrenItem.typeName,
- // RQViewModelIDKey : childrenItem.typeDescribe? : @"",
- // RQViewModelUtilKey : childrenItem.videos,
- // RQViewCommonValueKey: self.viewModel.indexPath,
- // }];
- // RQVideoDetailSubPageViewController *videoDetailSubPageViewController = [[RQVideoDetailSubPageViewController alloc] initWithViewModel:videoDetailSubPageViewModel];
- ChildrenItem *childrenItem = _viewModel.childrenItemArr[index];
-
- RQHomeSubPageVideoScrollViewModel *homeSubPageVideoScrollViewModel = [[RQHomeSubPageVideoScrollViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:@{
- RQViewModelUtilKey : self.viewModel.treeListModel,
- RQVideoItemIndexKey : @(index),
- RQVideoItemIndexPathKey : [NSIndexPath indexPathForRow:index inSection:self.viewModel.section],
- RQHomePageSubjectTypeKey : @(self.viewModel.homePageSubjectType),
- RQViewCommonValueKey : childrenItem.videos,
- }];
- RQHomeSubPageVideoScrollViewController *homeSubPageVideoScrollViewController = [[RQHomeSubPageVideoScrollViewController alloc] initWithViewModel:homeSubPageVideoScrollViewModel];
- homeSubPageVideoScrollViewController.superCollectionView = self.superCollectionView;
- homeSubPageVideoScrollViewController.view.frame = self.frame;
- return homeSubPageVideoScrollViewController;
- }
- #pragma mark - JXCategoryViewDelegate
- - (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
-
- }
- - (void)categoryView:(JXCategoryBaseView *)categoryView didClickSelectedItemAtIndex:(NSInteger)index {
- // ChildrenItem *childrenItem = (self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectTwo || self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectThree)? self.viewModel.treeListModel.children.lastObject : self.viewModel.treeListModel.children[index];
- // [RQNotificationCenter postNotificationName:RQPlayVideoUrlNotification object:@{
- // RQPlayVideoItemKey : childrenItem.videos.firstObject,
- // RQPlayVideoItemArrKey : childrenItem.videos,
- // }];
- }
- - (void)categoryView:(JXCategoryBaseView *)categoryView didScrollSelectedItemAtIndex:(NSInteger)index {
- // ChildrenItem *childrenItem = (self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectTwo || self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectThree)? self.viewModel.treeListModel.children.lastObject : self.viewModel.treeListModel.children[index];
- // [RQNotificationCenter postNotificationName:RQPlayVideoUrlNotification object:@{
- // RQPlayVideoItemKey : childrenItem.videos.firstObject,
- // RQPlayVideoItemArrKey : childrenItem.videos,
- // }];
- }
- #pragma mark - JXPagerMainTableViewGestureDelegate
- - (BOOL)mainTableViewGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
- if ([self checkIsNestContentScrollView:(UIScrollView *)gestureRecognizer.view] || [self checkIsNestContentScrollView:(UIScrollView *)otherGestureRecognizer.view]) {
- //如果交互的是嵌套的contentScrollView,证明在左右滑动,就不允许同时响应
- return NO;
- }
- return [gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]];
- }
- - (BOOL)checkIsNestContentScrollView:(UIScrollView *)scrollView {
- for (RQHomeSubPageVideoScrollViewController *list in self.pagerView.validListDict.allValues) {
- if (list.contentScrollView == scrollView) {
- return YES;
- }
- }
- return NO;
- }
- #pragma mark - LazyLoad
- - (JXPagerView *)pagerView {
- if (!_pagerView) {
- _pagerView = [[JXPagerView alloc] initWithDelegate:self];
- _pagerView.mainTableView.gestureDelegate = self;
- _pagerView.mainTableView.bounces = NO;
- _pagerView.layer.cornerRadius = 10;
- _pagerView.clipsToBounds = YES;
- // _pagerView.pinSectionHeaderVerticalOffset = self.cycleScrollViewHeight;
- _pagerView.isMirror = YES;
- }
- return _pagerView;
- }
- - (JXCategoryTitleBackgroundView *)categoryView {
- if (!_categoryView) {
- _categoryView = [[JXCategoryTitleBackgroundView alloc] init];
- _categoryView.delegate = self;
-
- _categoryView.titles = self.titles;
- _categoryView.titleSelectedColor = UIColor.whiteColor;
- _categoryView.titleColor = UIColor.whiteColor;
- _categoryView.titleFont = RQMediumFont(11);
- _categoryView.titleNumberOfLines = 0;
- _categoryView.titleSelectedFont = RQMediumFont(11);
- _categoryView.titleColorGradientEnabled = YES;
-
- _categoryView.contentEdgeInsetLeft = 3;
- _categoryView.contentEdgeInsetRight = 3;
- _categoryView.cellWidth = self.cellWeight;
- _categoryView.cellSpacing = 3;
-
- _categoryView.backgroundColor = RQ_MAIN_TEXT_COLOR_1;
- _categoryView.normalBackgroundColor = RQ_MAIN_TEXT_COLOR_3;
- _categoryView.backgroundHeight = self.cellWeight * (37.f / 65.f);
- _categoryView.borderLineWidth = 0;
-
- JXCategoryIndicatorImageView *indicatorImageView1 = [[JXCategoryIndicatorImageView alloc] init];
- indicatorImageView1.componentPosition = JXCategoryComponentPosition_Top;
- indicatorImageView1.indicatorImageView.image = RQImageNamed(@"arrowUP");
- indicatorImageView1.indicatorImageViewSize = CGSizeMake(self.cellWeight * (11 / 65.f), self.cellWeight * (11 / 65.f) * (4.3f / 11.f));
- _categoryView.indicators = @[indicatorImageView1];
- _categoryView.defaultSelectedIndex = 0;
- /// !!!: 将列表容器视图关联到 categoryView
- _categoryView.listContainer = (id<JXCategoryViewListContainer>)self.pagerView.listContainerView;
- }
- return _categoryView;
- }
- - (NSArray<NSString *> *)titles {
- if (!_titles) {
- _titles = @[@"侧方停车", @"倒车入库", @"坡道定点\n停车与起步", @"曲线行驶", @"直角转弯"];
- }
- return _titles;
- }
- - (float)cellWeight {
- return (RQ_SCREEN_WIDTH - 32 - (3 * 6)) / 5.f;
- }
- @end
|