// // RQVipCenterSubViewController.m // jiaPei // // Created by 张嵘 on 2022/8/8. // Copyright © 2022 JCZ. All rights reserved. // #import "RQVipCenterSubViewController.h" @interface RQVipCenterSubViewController () /// viewModel @property (nonatomic, readonly, strong) RQVipCenterSubViewModel *viewModel; @property (nonatomic, readwrite, copy) void(^scrollCallback)(UIScrollView *scrollView); @property (nonatomic, readwrite, strong) JXPagerView *pagerView; @property (nonatomic, readwrite, strong) JXCategoryTitleView *categoryView; @property (nonatomic, readwrite, strong) NSArray *titles; @property (nonatomic, readwrite, strong) UIScrollView *currentListView; @end @implementation RQVipCenterSubViewController @dynamic viewModel; #pragma mark - SystemMethod - (void)viewDidLoad { [super viewDidLoad]; /// 初始化 [self rq_setup]; } - (void)viewDidLayoutSubviews { [super viewDidLayoutSubviews]; self.pagerView.frame = CGRectMake(0, RQ_FIT_HORIZONTAL(102.f) + 32.f, RQ_SCREEN_WIDTH, RQ_SCREEN_HEIGHT - RQ_APPLICATION_NAV_BAR_HEIGHT - RQ_APPLICATION_STATUS_BAR_HEIGHT - 0.f - RQ_FIT_HORIZONTAL(102.f) - 32.f - RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT); } #pragma mark - PrivateMethods /// 初始化 - (void)rq_setup { /// set up ... [self.view addSubview:self.pagerView]; } #pragma mark - JXPagerViewDelegate - (UIView *)tableHeaderViewInPagerView:(JXPagerView *)pagerView { return [UIView new]; } - (NSUInteger)tableHeaderViewHeightInPagerView:(JXPagerView *)pagerView { return 0.f; } - (NSUInteger)heightForPinSectionHeaderInPagerView:(JXPagerView *)pagerView { return 0.f; } - (UIView *)viewForPinSectionHeaderInPagerView:(JXPagerView *)pagerView { return self.categoryView; } - (NSInteger)numberOfListsInPagerView:(JXPagerView *)pagerView { //和categoryView的item数量一致 return self.categoryView.titles.count; } - (id)pagerView:(JXPagerView *)pagerView initListAtIndex:(NSInteger)index { @weakify(self); RQVipCenterSubListViewModel *vipCenterSubListViewModel = [[RQVipCenterSubListViewModel alloc] initWithServices:self.viewModel.services params:@{RQHomePageSubjectTypeKey : @(self.viewModel.homePageSubjectType)}]; RQVipCenterSubListViewController *vipCenterSubListViewController = [[RQVipCenterSubListViewController alloc] initWithViewModel:vipCenterSubListViewModel]; vipCenterSubListViewController.scrollCallback = ^(UIScrollView *scrollView) { @strongify(self); self.scrollCallback(scrollView); }; self.currentListView = vipCenterSubListViewController.collectionView; return vipCenterSubListViewController; } - (void)pagerView:(JXPagerView *)pagerView mainTableViewDidScroll:(UIScrollView *)scrollView { } #pragma mark - JXCategoryViewDelegate - (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index { self.navigationController.interactivePopGestureRecognizer.enabled = (index == 0); //根据选中的下标,实时更新currentListView RQHomePageSubjectOneOrFourViewController *list = (RQHomePageSubjectOneOrFourViewController *)self.pagerView.listContainerView.validListDict[@(index)]; self.currentListView = list.collectionView; } - (void)categoryView:(JXCategoryBaseView *)categoryView didClickSelectedItemAtIndex:(NSInteger)index { } - (void)categoryView:(JXCategoryBaseView *)categoryView didScrollSelectedItemAtIndex:(NSInteger)index { } #pragma mark - JXPagerMainTableViewGestureDelegate - (BOOL)mainTableViewGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { //禁止categoryView左右滑动的时候,上下和左右都可以滚动 // NSLog(@"%@--------%@",NSStringFromClass([gestureRecognizer.view class]),NSStringFromClass([otherGestureRecognizer.view class])); if (otherGestureRecognizer == self.categoryView.collectionView.panGestureRecognizer) { return NO; } return [gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]; } - (void)scrollViewDidScroll:(UIScrollView *)scrollView { !self.scrollCallback ?: self.scrollCallback(scrollView); } #pragma mark - JXPagingViewListViewDelegate - (UIView *)listView { return self.view; } - (UIScrollView *)listScrollView { return self.collectionView; } - (void)listViewDidScrollCallback:(void (^)(UIScrollView *))callback { self.scrollCallback = callback; } #pragma mark - LazyLoad - (JXPagerView *)pagerView { if (!_pagerView) { _pagerView = [[JXPagerView alloc] initWithDelegate:self]; _pagerView.mainTableView.gestureDelegate = self; _pagerView.mainTableView.bounces = NO; _pagerView.listContainerView.categoryNestPagingEnabled = YES; _pagerView.listContainerView.frame = CGRectMake(0, RQ_FIT_HORIZONTAL(102.f) + 32.f, RQ_SCREEN_WIDTH, RQ_SCREEN_HEIGHT - RQ_APPLICATION_NAV_BAR_HEIGHT - RQ_APPLICATION_STATUS_BAR_HEIGHT - 88.f - RQ_FIT_HORIZONTAL(102.f) - 32.f - RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT); self.contentScrollView = _pagerView.listContainerView.contentScrollView; } return _pagerView; } - (JXCategoryTitleView *)categoryView { if (!_categoryView) { _categoryView = [[JXCategoryTitleView alloc] init]; _categoryView.titles = self.titles; _categoryView.backgroundColor = [UIColor whiteColor]; _categoryView.titleSelectedColor = RQ_MAIN_TEXT_COLOR_1; _categoryView.titleColor = RQ_MAIN_TEXT_COLOR_2; _categoryView.titleFont = RQRegularFont(16); _categoryView.titleSelectedFont = RQRegularFont(18); _categoryView.titleColorGradientEnabled = YES; _categoryView.titleLabelZoomEnabled = NO; _categoryView.contentScrollViewClickTransitionAnimationEnabled = NO; _categoryView.titleLabelZoomSelectedVerticalOffset = 0.0f; _categoryView.titleLabelVerticalOffset = 6.f; _categoryView.cellWidth = (RQ_SCREEN_WIDTH - 32.f) / self.titles.count; _categoryView.cellSpacing = 0; JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc] init]; lineView.indicatorColor = RQ_MAIN_COLOR; lineView.indicatorWidth = 20; lineView.indicatorHeight = 4; _categoryView.indicators = @[lineView]; _categoryView.defaultSelectedIndex = 0; _categoryView.listContainer = (id)self.pagerView.listContainerView; _categoryView.delegate = self; } return _categoryView; } - (NSArray *)titles { return @[@""]; } @end