VipLessonContentViewController.m 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. //
  2. // VipLessonContentViewController.m
  3. // jiaPei
  4. //
  5. // Created by 张嵘 on 2019/6/27.
  6. // Copyright © 2019 JCZ. All rights reserved.
  7. //
  8. #import "VipLessonContentViewController.h"
  9. #import "VipLessonCollectionTypeOneCell.h"
  10. #import "VipLessonCollectionTypeTwoCell.h"
  11. #import "VipLessonCollectionTypeThreeCell.h"
  12. #import "VipLessonCollectionReusableView.h"
  13. #import "VipExamViewController.h"
  14. @interface VipLessonContentViewController () <UICollectionViewDelegate, UICollectionViewDataSource>
  15. @property (nonatomic, readwrite, strong) UICollectionView *collectionView;
  16. @property (nonatomic, readwrite, copy) NSArray *headerTitlesArr;
  17. @property (nonatomic, readwrite, copy) NSArray *secTwoImagesArr;
  18. @property (nonatomic, readwrite, copy) NSArray *secTwoTitlesArr;
  19. @property (nonatomic, readwrite, copy) NSArray *secThreeImagesArr;
  20. @property (nonatomic, readwrite, copy) NSArray *secThreeTitlesArr;
  21. @property (nonatomic, readwrite, copy) NSArray *secThreeSubTitlesArr;
  22. @end
  23. @implementation VipLessonContentViewController
  24. #pragma mark - Life Cycle
  25. - (void)viewDidLoad {
  26. [super viewDidLoad];
  27. [self.view addSubview:self.collectionView];
  28. [self.collectionView registerNib:[UINib nibWithNibName:@"VipLessonCollectionTypeOneCell" bundle:nil] forCellWithReuseIdentifier:@"VipLessonCollectionTypeOneCell"];
  29. [self.collectionView registerNib:[UINib nibWithNibName:@"VipLessonCollectionTypeTwoCell" bundle:nil] forCellWithReuseIdentifier:@"VipLessonCollectionTypeTwoCell"];
  30. [self.collectionView registerNib:[UINib nibWithNibName:@"VipLessonCollectionTypeThreeCell" bundle:nil] forCellWithReuseIdentifier:@"VipLessonCollectionTypeThreeCell"];
  31. [self.collectionView registerNib:[UINib nibWithNibName:@"VipLessonCollectionReusableView" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"VipLessonCollectionReusableView"];
  32. }
  33. #pragma mark - UICollectionViewDelegate, UICollectionViewDataSource
  34. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  35. return 3;
  36. }
  37. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  38. switch (section) {
  39. case 0:
  40. return 1;
  41. case 1:
  42. return 3;
  43. case 2:
  44. return 2;
  45. default:
  46. return 0;
  47. }
  48. }
  49. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  50. switch (indexPath.section) {
  51. case 0:
  52. return CGSizeMake(kScreenWidth - (8 * 2), (kScreenWidth - (8 * 2)) * 0.25);
  53. case 1:
  54. return CGSizeMake((kScreenWidth - (8 * 4))/3.0, ((kScreenWidth - (8 * 4))/3.0) * (2.0 / 3.0));
  55. case 2:
  56. return CGSizeMake((kScreenWidth - (8 * 3))/2.0, (kScreenWidth - (8 * 3))/2.0 * (7.0 / 16.0));
  57. default:
  58. return CGSizeZero;
  59. }
  60. }
  61. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
  62. return CGSizeMake(kScreenWidth, 50);
  63. }
  64. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
  65. if (kind == UICollectionElementKindSectionHeader) {
  66. VipLessonCollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"VipLessonCollectionReusableView" forIndexPath:indexPath];
  67. headerView.rightTitleLabel.text = self.headerTitlesArr[indexPath.section];
  68. return headerView;
  69. } else {
  70. return nil;
  71. }
  72. }
  73. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  74. switch (indexPath.section) {
  75. case 0: {
  76. VipLessonCollectionTypeOneCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"VipLessonCollectionTypeOneCell" forIndexPath:indexPath];
  77. return cell;
  78. }
  79. case 1: {
  80. VipLessonCollectionTypeTwoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"VipLessonCollectionTypeTwoCell" forIndexPath:indexPath];
  81. cell.imageView.image = [UIImage imageNamed:self.secTwoImagesArr[indexPath.row]];
  82. cell.titleLabel.text = self.secTwoTitlesArr[indexPath.row];
  83. return cell;
  84. }
  85. case 2: {
  86. VipLessonCollectionTypeThreeCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"VipLessonCollectionTypeThreeCell" forIndexPath:indexPath];
  87. cell.imageView.image = [UIImage imageNamed:self.secThreeImagesArr[indexPath.row]];
  88. cell.titleLabel.text = self.secThreeTitlesArr[indexPath.row];
  89. cell.subTItleLabel.text = self.secThreeSubTitlesArr[indexPath.row];
  90. return cell;
  91. }
  92. default:
  93. return nil;
  94. }
  95. }
  96. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  97. [collectionView deselectItemAtIndexPath:indexPath animated:YES];
  98. VipExamViewController *vc = [[VipExamViewController alloc] init];
  99. [self navPushHideTabbarToVC:vc];
  100. }
  101. /// collectinView section header 在高版本存在系统BUG,需要设置zPosition = 0.0
  102. - (void)collectionView:(UICollectionView *)collectionView willDisplaySupplementaryView:(UICollectionReusableView *)view forElementKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)indexPath {
  103. view.layer.zPosition = 0.0;
  104. }
  105. #pragma mark - Lazy Load
  106. - (UICollectionView *)collectionView {
  107. if (!_collectionView) {
  108. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  109. layout.itemSize = CGSizeMake(100, 100);
  110. layout.sectionInset = UIEdgeInsetsMake(0, 8, 0, 8);
  111. layout.minimumLineSpacing = 8;
  112. layout.minimumInteritemSpacing = 8;
  113. _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) collectionViewLayout:layout];
  114. _collectionView.dataSource = self;
  115. _collectionView.delegate = self;
  116. _collectionView.backgroundColor = [UIColor whiteColor];
  117. }
  118. return _collectionView;
  119. }
  120. - (NSArray *)headerTitlesArr {
  121. return @[@"01 速成课程", @"02 秒懂技巧", @"03 精选课程"];
  122. }
  123. - (NSArray *)secTwoImagesArr {
  124. return @[@"fast_voice_icon", @"fast_video_icon", @"fast_class_icon"];
  125. }
  126. - (NSArray *)secTwoTitlesArr {
  127. return @[@"语音技巧", @"视频技巧", @"考点归类速记"];
  128. }
  129. - (NSArray *)secThreeImagesArr {
  130. return @[@"threeDay", @"errorTopic"];
  131. }
  132. - (NSArray *)secThreeTitlesArr {
  133. return @[@"三天特训", @"易错题"];
  134. }
  135. - (NSArray *)secThreeSubTitlesArr {
  136. return @[@"冲刺100分", @"攻克难点"];
  137. }
  138. @end