// // YMRankingListViewController.m // MSYOUPAI // // Created by YoMi on 2024/2/14. // Copyright © 2024 MS. All rights reserved. // #import "YMRankingListViewController.h" #import "JXCategoryTitleBackgroundView.h" #import "YMRankingListView.h" @interface YMRankingListViewController () /// 滚动视图回调 @property (nonatomic, copy) void(^scrollCallback)(UIScrollView *scrollView); /// 列表VM @property (nonatomic, strong) YMRankingListMainCategoryViewModel *viewModel; /// 分类标题视图 @property (nonatomic, strong) JXCategoryTitleBackgroundView *categoryView; /// 分类列表容器视图 @property (nonatomic, strong) JXCategoryListContainerView *listContainerView; /// 当前列表视图 @property (nonatomic, strong) UIScrollView *currentListView; @end @implementation YMRankingListViewController @dynamic viewModel; - (void)viewDidLoad { [super viewDidLoad]; [self setNavHidden:YES]; self.view.backgroundColor = UIColor.clearColor; } - (void)ym_setupViews{ [self.view addSubview:self.categoryView]; [self.view addSubview:self.listContainerView]; [self.view setNeedsUpdateConstraints]; [self.view updateConstraintsIfNeeded]; } - (void)updateViewConstraints{ [self.categoryView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.view).offset(5); make.left.equalTo(self.view).offset(adapt(60)); make.right.equalTo(self.view).offset(adapt(-60)); make.height.mas_equalTo(adapt(34)); }]; [self.listContainerView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.categoryView.mas_bottom); make.left.equalTo(self.view).offset(adapt(0)); make.right.equalTo(self.view).offset(adapt(0)); make.bottom.equalTo(self.view); }]; self.contentScrollView = self.listContainerView.scrollView; self.categoryView.listContainer = self.listContainerView; [super updateViewConstraints]; } - (void)ym_bindViewModel{ } - (UIView *)listView { return self.view; } - (UIScrollView *)listScrollView { return self.currentListView; } - (void)listViewDidScrollCallback:(void (^)(UIScrollView *))callback { self.scrollCallback = callback; } - (void)listScrollViewWillResetContentOffset { //当前的listScrollView需要重置的时候,就把所有列表的contentOffset都重置了 for (YMRankingListView *list in self.listContainerView.validListDict.allValues) { list.contentScrollView.contentOffset = CGPointZero; } } #pragma mark - JXCategoryViewDelegate - (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index { //根据选中的下标,实时更新currentListView YMRankingListView *listView = (YMRankingListView *)self.listContainerView.validListDict[@(index)]; self.currentListView = listView.contentScrollView; } #pragma mark - JXCategoryListContainerViewDelegate - (NSInteger)numberOfListsInlistContainerView:(JXCategoryListContainerView *)listContainerView { return self.categoryView.titles.count; } - (id)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index { __weak typeof(self) weakSelf = self; YMRankingListView *listView = [[YMRankingListView alloc]init]; listView.backgroundColor = UIColor.clearColor; [listView ym_bindViewModel:self.viewModel.subCategoryVMDataArray[index]]; listView.scrollCallback = ^(UIScrollView *scrollView) { weakSelf.scrollCallback(scrollView); }; self.currentListView = listView.contentScrollView; return listView; } - (JXCategoryTitleBackgroundView *)categoryView{ if (!_categoryView) { _categoryView = [[JXCategoryTitleBackgroundView alloc]init]; _categoryView.layer.cornerRadius = adapt(17); _categoryView.layer.masksToBounds = true; _categoryView.backgroundColor = HexColorFromRGBA(0xFFFFFF, 0.2); _categoryView.delegate = self; _categoryView.defaultSelectedIndex = 2; _categoryView.titles = [self.viewModel.subCategoryVMDataArray.rac_sequence map:^id _Nullable(YMRankingListSubCategoryViewModel * _Nullable viewModel) { return viewModel.customNavTitle; }].array; _categoryView.titleLabelZoomEnabled = NO; _categoryView.titleColorGradientEnabled = YES; _categoryView.titleSelectedColor = HexColorFromRGB(0x2C4385); _categoryView.titleSelectedFont = LCFont(14); _categoryView.titleColor = HexColorFromRGB(0xFFFFFF); _categoryView.titleFont = LCFont(14); _categoryView.averageCellSpacingEnabled = YES; _categoryView.cellSpacing = adapt(5); _categoryView.contentEdgeInsetLeft = 0; _categoryView.contentEdgeInsetRight = 0; _categoryView.normalBackgroundColor = UIColor.clearColor; _categoryView.selectedBackgroundColor = HexColorFromRGB(0xFFFFFF); _categoryView.normalBorderColor = UIColor.clearColor; _categoryView.selectedBorderColor = UIColor.clearColor; _categoryView.borderLineWidth = 1; _categoryView.backgroundCornerRadius = adapt(16); _categoryView.backgroundWidth = JXCategoryViewAutomaticDimension; _categoryView.backgroundHeight = adapt(32); } return _categoryView; } //- (JXCategoryTitleBackgroundView *)categoryView{ // if (!_categoryView) { // _categoryView = [[JXCategoryTitleBackgroundView alloc]init]; // _categoryView.backgroundColor = UIColor.whiteColor; // _categoryView.delegate = self; // _categoryView.defaultSelectedIndex = 2; // _categoryView.titles = [self.viewModel.subCategoryVMDataArray.rac_sequence map:^id _Nullable(YMRankingListSubCategoryViewModel * _Nullable viewModel) { // return viewModel.customNavTitle; // }].array; // _categoryView.titleLabelZoomEnabled = NO; // _categoryView.titleColorGradientEnabled = YES; // _categoryView.titleSelectedColor = HexColorFromRGB(0xFFFFFF); // _categoryView.titleSelectedFont = LCFont(13); // _categoryView.titleColor = HexColorFromRGB(0xFFFFFF); // _categoryView.titleFont = LCFont(13); // _categoryView.averageCellSpacingEnabled = YES; // _categoryView.cellSpacing = adapt(5); // _categoryView.contentEdgeInsetLeft = adapt(25); // _categoryView.contentEdgeInsetRight = adapt(25); // _categoryView.normalBackgroundColor = HexColorFromRGBA(0xFFFFFF, 0.15); // _categoryView.normalBorderColor = UIColor.clearColor; // _categoryView.selectedBackgroundColor = HexColorFromRGB(0xE23C9E); // _categoryView.selectedBorderColor = UIColor.clearColor; // _categoryView.borderLineWidth = 1; // _categoryView.backgroundCornerRadius = adapt(28)/2; // _categoryView.backgroundWidth = JXCategoryViewAutomaticDimension; // _categoryView.backgroundHeight = adapt(28); // _categoryView.backgroundColor = UIColor.clearColor; // } // return _categoryView; //} - (JXCategoryListContainerView *)listContainerView{ if (!_listContainerView) { _listContainerView = [[JXCategoryListContainerView alloc] initWithType:JXCategoryListContainerType_CollectionView delegate:self]; _listContainerView.defaultSelectedIndex = 2; _listContainerView.scrollView.showsVerticalScrollIndicator = NO; _listContainerView.scrollView.showsHorizontalScrollIndicator = NO; _listContainerView.scrollView.backgroundColor = UIColor.clearColor; _listContainerView.listCellBackgroundColor = UIColor.clearColor; } return _listContainerView; } @end