RQHomePageSubjectOneOrFourViewController.m 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. //
  2. // RQHomePageSubjectOneOrFourViewController.m
  3. // SDJK
  4. //
  5. // Created by 张嵘 on 2021/7/29.
  6. //
  7. #import "RQHomePageSubjectOneOrFourViewController.h"
  8. @interface RQHomePageSubjectOneOrFourViewController ()
  9. /// viewModel
  10. @property (nonatomic, readonly, strong) RQHomePageSubjectOneOrFourViewModel *viewModel;
  11. @end
  12. @implementation RQHomePageSubjectOneOrFourViewController
  13. @dynamic viewModel;
  14. #pragma mark - SystemMethod
  15. - (void)viewDidLoad {
  16. [super viewDidLoad];
  17. /// 初始化
  18. [self rq_setup];
  19. }
  20. - (void)viewDidLayoutSubviews {
  21. [super viewDidLayoutSubviews];
  22. self.view.frame = CGRectMake(0, 0, RQ_SCREEN_WIDTH, RQ_SCREEN_HEIGHT);
  23. }
  24. #pragma mark - PrivateMethods
  25. /// 初始化
  26. - (void)rq_setup {
  27. /// set up ...
  28. self.collectionView.bounces = NO;
  29. self.collectionView.backgroundColor = UIColor.clearColor;
  30. }
  31. #pragma mark - OverrideMethods
  32. /// 配置tableView的区域
  33. - (UIEdgeInsets)contentInset {
  34. return UIEdgeInsetsMake((self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectTwo || self.viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectThree)? 24 : 0, 0, RQ_APPLICATION_TOP_BAR_HEIGHT + RQHeightForPinSectionHeaderInPagerView_One + RQHeightForPinSectionHeaderInPagerView_Two + RQ_APPLICATION_TAB_BAR_HEIGHT + RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT, 0);
  35. }
  36. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath {
  37. RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section];
  38. RQCommonCollecttionItemViewModel *itemViewModel = groupViewModel.itemViewModels[indexPath.row];
  39. return [NSClassFromString(itemViewModel.itemClassName) cellWithCollectionView:collectionView forIndexPath:indexPath];
  40. }
  41. - (void)configureCell:(RQCommonCell *)cell atIndexPath:(NSIndexPath *)indexPath withObject:(id)object {
  42. [cell bindViewModel:object];
  43. }
  44. - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
  45. RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[section];
  46. if (groupViewModel.itemViewModels.count > 0) {
  47. if ([groupViewModel.itemViewModels.firstObject isKindOfClass:[RQFreeTryItemViewModel class]]) {
  48. return UIEdgeInsetsMake(18, 16, 20, 16);
  49. } else if ([groupViewModel.itemViewModels.firstObject isKindOfClass:[RQHomeSubPageItemViewModel class]]) {
  50. return UIEdgeInsetsZero;
  51. } else if ([groupViewModel.itemViewModels.firstObject isKindOfClass:[RQHomePageJiaoGuan12123ItemViewModel class]]) {
  52. return UIEdgeInsetsMake(4, 16, 0, 16);
  53. } else {
  54. return UIEdgeInsetsMake(0, 16, 0, 16);
  55. }
  56. } else {
  57. return UIEdgeInsetsMake(0, 16, 0, 16);
  58. }
  59. }
  60. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
  61. return RQ_APPLICATION_COMMON_SPACE_10;
  62. }
  63. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
  64. return 11.f;
  65. }
  66. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
  67. @weakify(self)
  68. // 如果是头视图
  69. if (kind == UICollectionElementKindSectionHeader) {
  70. RQHomeSubPageVideoHeaderCollectionReusableView *headerView = [RQHomeSubPageVideoHeaderCollectionReusableView reusableViewWithCollectionView:collectionView OfKind:kind forIndexPath:indexPath];
  71. RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section];
  72. [headerView bindViewModel:groupViewModel];
  73. headerView.headerContentLabel.hidden = NO;
  74. headerView.footerContentLabel.hidden = YES;
  75. return headerView;
  76. } else {
  77. RQCommonReusableView *footerView = [RQCommonReusableView reusableViewWithCollectionView:collectionView OfKind:kind forIndexPath:indexPath];
  78. RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section];
  79. [footerView bindViewModel:groupViewModel];
  80. footerView.headerContentLabel.hidden = YES;
  81. footerView.footerContentLabel.hidden = NO;
  82. footerView.footerContentLabel.textAlignment = NSTextAlignmentCenter;
  83. if ([groupViewModel.groupModel.footer isEqualToString:@"查看更多 >"]) {
  84. [footerView setTapActionWithBlock:^(UITapGestureRecognizer *tap) {
  85. @strongify(self)
  86. RQDspVideoDetailViewModel *viewModel = [[RQDspVideoDetailViewModel alloc] initWithServices:self.viewModel.services params:@{
  87. RQViewCommonValueKey: [NSIndexPath indexPathForRow:6 inSection:0],
  88. }];
  89. [self.viewModel.services pushViewModel:viewModel animated:YES];
  90. }];
  91. }
  92. return footerView;
  93. }
  94. }
  95. #pragma mark - UITableViewDelegate & UITableViewDataSource
  96. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  97. !self.scrollCallback ?: self.scrollCallback(scrollView);
  98. }
  99. #pragma mark - JXPagerViewListViewDelegate
  100. - (UIView *)listView {
  101. return self.view;
  102. }
  103. - (UIScrollView *)listScrollView {
  104. return self.collectionView;
  105. }
  106. - (void)listViewDidScrollCallback:(void (^)(UIScrollView *))callback {
  107. self.scrollCallback = callback;
  108. }
  109. @end