RQErrorAndCollectViewController.m 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. //
  2. // RQErrorAndCollectViewController.m
  3. // jiaPei
  4. //
  5. // Created by 张嵘 on 2022/8/3.
  6. // Copyright © 2022 JCZ. All rights reserved.
  7. //
  8. #import "RQErrorAndCollectViewController.h"
  9. @interface RQErrorAndCollectViewController () <JXCategoryViewDelegate, JXPagerViewDelegate, JXPagerSmoothViewDataSource>
  10. /// viewModel
  11. @property (nonatomic, readonly, strong) RQErrorAndCollectViewModel *viewModel;
  12. @property (nonatomic, readwrite, strong) JXPagerSmoothView *pagerView;
  13. @property (nonatomic, readwrite, strong) JXCategoryTitleView *categoryView;
  14. @property (nonatomic, readwrite, copy) NSArray <NSString *> *titles;
  15. @end
  16. @implementation RQErrorAndCollectViewController
  17. @dynamic viewModel;
  18. #pragma mark - SystemMethod
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. /// 初始化
  22. [self rq_setup];
  23. }
  24. - (void)viewDidLayoutSubviews {
  25. [super viewDidLayoutSubviews];
  26. self.pagerView.frame = CGRectMake(0, (RQ_APPLICATION_NAV_BAR_HEIGHT + RQ_APPLICATION_STATUS_BAR_HEIGHT), RQ_SCREEN_WIDTH, RQ_SCREEN_HEIGHT - (RQ_APPLICATION_NAV_BAR_HEIGHT + RQ_APPLICATION_STATUS_BAR_HEIGHT) - RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT);
  27. }
  28. - (void)dealloc {
  29. self.categoryView.delegate = nil;
  30. self.categoryView = nil;
  31. self.pagerView = nil;
  32. }
  33. #pragma mark - PrivateMethods
  34. /// 初始化
  35. - (void)rq_setup {
  36. /// set up ...
  37. [self.view addSubview:self.pagerView];
  38. self.navigationItem.titleView = self.categoryView;
  39. }
  40. #pragma mark - JXPagerSmoothView
  41. - (UIView *)viewForPagerHeaderInPagerView:(JXPagerSmoothView *)pagerView {
  42. return [UIView new];
  43. }
  44. - (CGFloat)heightForPagerHeaderInPagerView:(JXPagerSmoothView *)pagerView {
  45. return 0;
  46. }
  47. - (CGFloat)heightForPinHeaderInPagerView:(JXPagerSmoothView *)pagerView {
  48. return 0.f;
  49. }
  50. - (UIView *)viewForPinHeaderInPagerView:(JXPagerSmoothView *)pagerView {
  51. return [UIView new];
  52. }
  53. - (NSInteger)numberOfListsInPagerView:(JXPagerSmoothView *)pagerView {
  54. //和categoryView的item数量一致
  55. return self.categoryView.titles.count;
  56. }
  57. - (id<JXPagerSmoothViewListViewDelegate>)pagerView:(JXPagerSmoothView *)pagerView initListAtIndex:(NSInteger)index {
  58. if (index == 0) {
  59. RQErrorViewModel *errorViewModel = [[RQErrorViewModel alloc] initWithServices:self.viewModel.services params:@{}];
  60. RQErrorViewController *errorViewController = [[RQErrorViewController alloc] initWithViewModel:errorViewModel];
  61. return errorViewController;
  62. } else {
  63. RQCollectViewModel *collectViewModel = [[RQCollectViewModel alloc] initWithServices:self.viewModel.services params:@{}];
  64. RQCollectViewController *collectViewController = [[RQCollectViewController alloc] initWithViewModel:collectViewModel];
  65. return collectViewController;
  66. }
  67. }
  68. #pragma mark - JXCategoryViewDelegate
  69. - (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
  70. self.navigationController.interactivePopGestureRecognizer.enabled = (index == 0);
  71. }
  72. #pragma mark - JXPagerMainTableViewGestureDelegate
  73. - (BOOL)mainTableViewGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
  74. //禁止categoryView左右滑动的时候,上下和左右都可以滚动
  75. if (otherGestureRecognizer == self.categoryView.collectionView.panGestureRecognizer) {
  76. return NO;
  77. }
  78. return [gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]];
  79. }
  80. #pragma mark - LazyLoad
  81. - (JXPagerSmoothView *)pagerView {
  82. if (!_pagerView) {
  83. _pagerView = [[JXPagerSmoothView alloc] initWithDataSource:self];
  84. }
  85. return _pagerView;
  86. }
  87. - (JXCategoryTitleView *)categoryView {
  88. if (!_categoryView) {
  89. CGFloat autoReadBtnWidth = RQ_FIT_HORIZONTAL(80.f);
  90. CGFloat autoReadBtnHeight = RQ_FIT_HORIZONTAL(28.f);
  91. _categoryView = [[JXCategoryTitleView alloc] initWithFrame:CGRectMake(0, 0, autoReadBtnWidth * 2, autoReadBtnHeight)];
  92. _categoryView.delegate = self;
  93. _categoryView.titles = self.titles;
  94. _categoryView.titleSelectedColor = UIColor.whiteColor;
  95. _categoryView.titleColor = RQ_MAIN_TEXT_COLOR_3;
  96. _categoryView.titleFont = RQRegularFont(13);
  97. _categoryView.titleSelectedFont = RQRegularFont(13);
  98. _categoryView.titleNumberOfLines = 0;
  99. _categoryView.layer.cornerRadius = autoReadBtnHeight / 2.f;
  100. _categoryView.layer.borderWidth = 1;
  101. _categoryView.layer.borderColor = RQColorFromHexString(@"#B8C0CC").CGColor;
  102. _categoryView.contentScrollViewClickTransitionAnimationEnabled = YES;
  103. _categoryView.backgroundColor = UIColor.whiteColor;
  104. _categoryView.contentEdgeInsetLeft = 0;
  105. _categoryView.contentEdgeInsetRight = 0;
  106. _categoryView.backgroundColor = RQ_MAIN_BACKGROUNDCOLOR;
  107. _categoryView.cellSpacing = 0;
  108. _categoryView.cellWidth = autoReadBtnWidth;
  109. JXCategoryIndicatorBackgroundView *backgroundView = [[JXCategoryIndicatorBackgroundView alloc] init];
  110. backgroundView.indicatorHeight = autoReadBtnHeight;
  111. backgroundView.indicatorWidth = autoReadBtnWidth;
  112. backgroundView.indicatorWidthIncrement = 0;
  113. backgroundView.indicatorColor = RQ_MAIN_COLOR;
  114. _categoryView.indicators = @[backgroundView];
  115. _categoryView.defaultSelectedIndex = 0;
  116. /// !!!: 将列表容器视图关联到 categoryView
  117. _categoryView.contentScrollView = self.pagerView.listCollectionView;
  118. }
  119. return _categoryView;
  120. }
  121. - (NSArray<NSString *> *)titles {
  122. return @[@"错题本", @"收藏题目"];
  123. }
  124. @end