YMRankingListViewController.m 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. //
  2. // YMRankingListViewController.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/2/14.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMRankingListViewController.h"
  9. #import "JXCategoryTitleBackgroundView.h"
  10. #import "YMRankingListView.h"
  11. @interface YMRankingListViewController ()<JXCategoryViewDelegate, JXCategoryListContainerViewDelegate>
  12. /// 滚动视图回调
  13. @property (nonatomic, copy) void(^scrollCallback)(UIScrollView *scrollView);
  14. /// 列表VM
  15. @property (nonatomic, strong) YMRankingListMainCategoryViewModel *viewModel;
  16. /// 分类标题视图
  17. @property (nonatomic, strong) JXCategoryTitleBackgroundView *categoryView;
  18. /// 分类列表容器视图
  19. @property (nonatomic, strong) JXCategoryListContainerView *listContainerView;
  20. /// 当前列表视图
  21. @property (nonatomic, strong) UIScrollView *currentListView;
  22. @end
  23. @implementation YMRankingListViewController
  24. @dynamic viewModel;
  25. - (void)viewDidLoad {
  26. [super viewDidLoad];
  27. [self setNavHidden:YES];
  28. self.view.backgroundColor = UIColor.clearColor;
  29. }
  30. - (void)ym_setupViews{
  31. [self.view addSubview:self.categoryView];
  32. [self.view addSubview:self.listContainerView];
  33. [self.view setNeedsUpdateConstraints];
  34. [self.view updateConstraintsIfNeeded];
  35. }
  36. - (void)updateViewConstraints{
  37. [self.categoryView mas_makeConstraints:^(MASConstraintMaker *make) {
  38. make.top.equalTo(self.view).offset(5);
  39. make.left.equalTo(self.view).offset(adapt(60));
  40. make.right.equalTo(self.view).offset(adapt(-60));
  41. make.height.mas_equalTo(adapt(34));
  42. }];
  43. [self.listContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
  44. make.top.equalTo(self.categoryView.mas_bottom);
  45. make.left.equalTo(self.view).offset(adapt(0));
  46. make.right.equalTo(self.view).offset(adapt(0));
  47. make.bottom.equalTo(self.view);
  48. }];
  49. self.contentScrollView = self.listContainerView.scrollView;
  50. self.categoryView.listContainer = self.listContainerView;
  51. [super updateViewConstraints];
  52. }
  53. - (void)ym_bindViewModel{
  54. }
  55. - (UIView *)listView {
  56. return self.view;
  57. }
  58. - (UIScrollView *)listScrollView {
  59. return self.currentListView;
  60. }
  61. - (void)listViewDidScrollCallback:(void (^)(UIScrollView *))callback {
  62. self.scrollCallback = callback;
  63. }
  64. - (void)listScrollViewWillResetContentOffset {
  65. //当前的listScrollView需要重置的时候,就把所有列表的contentOffset都重置了
  66. for (YMRankingListView *list in self.listContainerView.validListDict.allValues) {
  67. list.contentScrollView.contentOffset = CGPointZero;
  68. }
  69. }
  70. #pragma mark - JXCategoryViewDelegate
  71. - (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
  72. //根据选中的下标,实时更新currentListView
  73. YMRankingListView *listView = (YMRankingListView *)self.listContainerView.validListDict[@(index)];
  74. self.currentListView = listView.contentScrollView;
  75. }
  76. #pragma mark - JXCategoryListContainerViewDelegate
  77. - (NSInteger)numberOfListsInlistContainerView:(JXCategoryListContainerView *)listContainerView {
  78. return self.categoryView.titles.count;
  79. }
  80. - (id<JXCategoryListContentViewDelegate>)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index {
  81. __weak typeof(self) weakSelf = self;
  82. YMRankingListView *listView = [[YMRankingListView alloc]init];
  83. listView.backgroundColor = UIColor.clearColor;
  84. [listView ym_bindViewModel:self.viewModel.subCategoryVMDataArray[index]];
  85. listView.scrollCallback = ^(UIScrollView *scrollView) {
  86. weakSelf.scrollCallback(scrollView);
  87. };
  88. self.currentListView = listView.contentScrollView;
  89. return listView;
  90. }
  91. - (JXCategoryTitleBackgroundView *)categoryView{
  92. if (!_categoryView) {
  93. _categoryView = [[JXCategoryTitleBackgroundView alloc]init];
  94. _categoryView.layer.cornerRadius = adapt(17);
  95. _categoryView.layer.masksToBounds = true;
  96. _categoryView.backgroundColor = HexColorFromRGBA(0xFFFFFF, 0.2);
  97. _categoryView.delegate = self;
  98. _categoryView.defaultSelectedIndex = 2;
  99. _categoryView.titles = [self.viewModel.subCategoryVMDataArray.rac_sequence map:^id _Nullable(YMRankingListSubCategoryViewModel * _Nullable viewModel) {
  100. return viewModel.customNavTitle;
  101. }].array;
  102. _categoryView.titleLabelZoomEnabled = NO;
  103. _categoryView.titleColorGradientEnabled = YES;
  104. _categoryView.titleSelectedColor = HexColorFromRGB(0x2C4385);
  105. _categoryView.titleSelectedFont = LCFont(14);
  106. _categoryView.titleColor = HexColorFromRGB(0xFFFFFF);
  107. _categoryView.titleFont = LCFont(14);
  108. _categoryView.averageCellSpacingEnabled = YES;
  109. _categoryView.cellSpacing = adapt(5);
  110. _categoryView.contentEdgeInsetLeft = 0;
  111. _categoryView.contentEdgeInsetRight = 0;
  112. _categoryView.normalBackgroundColor = UIColor.clearColor;
  113. _categoryView.selectedBackgroundColor = HexColorFromRGB(0xFFFFFF);
  114. _categoryView.normalBorderColor = UIColor.clearColor;
  115. _categoryView.selectedBorderColor = UIColor.clearColor;
  116. _categoryView.borderLineWidth = 1;
  117. _categoryView.backgroundCornerRadius = adapt(16);
  118. _categoryView.backgroundWidth = JXCategoryViewAutomaticDimension;
  119. _categoryView.backgroundHeight = adapt(32);
  120. }
  121. return _categoryView;
  122. }
  123. //- (JXCategoryTitleBackgroundView *)categoryView{
  124. // if (!_categoryView) {
  125. // _categoryView = [[JXCategoryTitleBackgroundView alloc]init];
  126. // _categoryView.backgroundColor = UIColor.whiteColor;
  127. // _categoryView.delegate = self;
  128. // _categoryView.defaultSelectedIndex = 2;
  129. // _categoryView.titles = [self.viewModel.subCategoryVMDataArray.rac_sequence map:^id _Nullable(YMRankingListSubCategoryViewModel * _Nullable viewModel) {
  130. // return viewModel.customNavTitle;
  131. // }].array;
  132. // _categoryView.titleLabelZoomEnabled = NO;
  133. // _categoryView.titleColorGradientEnabled = YES;
  134. // _categoryView.titleSelectedColor = HexColorFromRGB(0xFFFFFF);
  135. // _categoryView.titleSelectedFont = LCFont(13);
  136. // _categoryView.titleColor = HexColorFromRGB(0xFFFFFF);
  137. // _categoryView.titleFont = LCFont(13);
  138. // _categoryView.averageCellSpacingEnabled = YES;
  139. // _categoryView.cellSpacing = adapt(5);
  140. // _categoryView.contentEdgeInsetLeft = adapt(25);
  141. // _categoryView.contentEdgeInsetRight = adapt(25);
  142. // _categoryView.normalBackgroundColor = HexColorFromRGBA(0xFFFFFF, 0.15);
  143. // _categoryView.normalBorderColor = UIColor.clearColor;
  144. // _categoryView.selectedBackgroundColor = HexColorFromRGB(0xE23C9E);
  145. // _categoryView.selectedBorderColor = UIColor.clearColor;
  146. // _categoryView.borderLineWidth = 1;
  147. // _categoryView.backgroundCornerRadius = adapt(28)/2;
  148. // _categoryView.backgroundWidth = JXCategoryViewAutomaticDimension;
  149. // _categoryView.backgroundHeight = adapt(28);
  150. // _categoryView.backgroundColor = UIColor.clearColor;
  151. // }
  152. // return _categoryView;
  153. //}
  154. - (JXCategoryListContainerView *)listContainerView{
  155. if (!_listContainerView) {
  156. _listContainerView = [[JXCategoryListContainerView alloc] initWithType:JXCategoryListContainerType_CollectionView delegate:self];
  157. _listContainerView.defaultSelectedIndex = 2;
  158. _listContainerView.scrollView.showsVerticalScrollIndicator = NO;
  159. _listContainerView.scrollView.showsHorizontalScrollIndicator = NO;
  160. _listContainerView.scrollView.backgroundColor = UIColor.clearColor;
  161. _listContainerView.listCellBackgroundColor = UIColor.clearColor;
  162. }
  163. return _listContainerView;
  164. }
  165. @end