NYBlockExerciseViewController.m 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //
  2. // NYBlockExerciseViewController.m
  3. // jiaPei
  4. //
  5. // Created by Ning.ge on 2024/12/5.
  6. // Copyright © 2024 JCZ. All rights reserved.
  7. //
  8. #import "NYBlockExerciseViewController.h"
  9. @interface NYBlockExerciseViewController ()
  10. /// viewModel
  11. @property (nonatomic, readonly, strong) NYBlockExerciseViewModel *viewModel;
  12. @end
  13. @implementation NYBlockExerciseViewController
  14. @dynamic viewModel;
  15. #pragma mark - SystemMethod
  16. - (void)viewDidLoad {
  17. [super viewDidLoad];
  18. /// 初始化
  19. [self rq_setup];
  20. }
  21. - (void)viewDidLayoutSubviews {
  22. [super viewDidLayoutSubviews];
  23. self.view.frame = CGRectMake(0, 0, RQ_SCREEN_WIDTH, RQ_SCREEN_HEIGHT);
  24. }
  25. #pragma mark - PrivateMethods
  26. /// 初始化
  27. - (void)rq_setup {
  28. /// set up ...
  29. self.collectionView.bounces = NO;
  30. self.collectionView.backgroundColor = UIColor.clearColor;
  31. }
  32. #pragma mark - OverrideMethods
  33. /// 配置collectionView的区域
  34. - (UIEdgeInsets)contentInset {
  35. return UIEdgeInsetsMake(RQ_APPLICATION_STATUS_BAR_HEIGHT + RQ_APPLICATION_NAV_BAR_HEIGHT, 0, 0, 0);
  36. }
  37. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath {
  38. RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section];
  39. RQCommonCollectionItemViewModel *itemViewModel = groupViewModel.itemViewModels[indexPath.row];
  40. UICollectionViewCell *cell = [NSClassFromString(itemViewModel.itemClassName) cellWithCollectionView:collectionView forIndexPath:indexPath];
  41. return cell;
  42. }
  43. - (void)configureCell:(RQCommonCell *)cell atIndexPath:(NSIndexPath *)indexPath withObject:(id)object {
  44. [cell bindViewModel:object];
  45. }
  46. - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
  47. return UIEdgeInsetsMake(0, 16, 0, 16);
  48. }
  49. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
  50. @weakify(self)
  51. RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section];
  52. // 如果是头视图
  53. if (kind == UICollectionElementKindSectionHeader) {
  54. if ([groupViewModel isKindOfClass:[NYBlockExerciseGroupViewModel class]]) {
  55. NYBlockExerciseHeaderView *headerView = [NYBlockExerciseHeaderView reusableViewWithCollectionView:collectionView OfKind:kind forIndexPath:indexPath];
  56. RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section];
  57. [headerView bindViewModel:groupViewModel];
  58. headerView.headerContentLabel.hidden = YES;
  59. headerView.footerContentLabel.hidden = YES;
  60. return headerView;
  61. }
  62. }
  63. RQCommonReusableView *headerView = [RQCommonReusableView reusableViewWithCollectionView:collectionView OfKind:kind forIndexPath:indexPath];
  64. [headerView bindViewModel:groupViewModel];
  65. headerView.headerContentLabel.hidden = YES;
  66. headerView.footerContentLabel.hidden = YES;
  67. return headerView;
  68. }
  69. @end