123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- //
- // VipLessonContentViewController.m
- // jiaPei
- //
- // Created by 张嵘 on 2019/6/27.
- // Copyright © 2019 JCZ. All rights reserved.
- //
- #import "VipLessonContentViewController.h"
- #import "VipLessonCollectionTypeOneCell.h"
- #import "VipLessonCollectionTypeTwoCell.h"
- #import "VipLessonCollectionTypeThreeCell.h"
- #import "VipLessonCollectionReusableView.h"
- #import "VipExamViewController.h"
- @interface VipLessonContentViewController () <UICollectionViewDelegate, UICollectionViewDataSource>
- @property (nonatomic, readwrite, strong) UICollectionView *collectionView;
- @property (nonatomic, readwrite, copy) NSArray *headerTitlesArr;
- @property (nonatomic, readwrite, copy) NSArray *secTwoImagesArr;
- @property (nonatomic, readwrite, copy) NSArray *secTwoTitlesArr;
- @property (nonatomic, readwrite, copy) NSArray *secThreeImagesArr;
- @property (nonatomic, readwrite, copy) NSArray *secThreeTitlesArr;
- @property (nonatomic, readwrite, copy) NSArray *secThreeSubTitlesArr;
- @end
- @implementation VipLessonContentViewController
- #pragma mark - Life Cycle
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self.view addSubview:self.collectionView];
- [self.collectionView registerNib:[UINib nibWithNibName:@"VipLessonCollectionTypeOneCell" bundle:nil] forCellWithReuseIdentifier:@"VipLessonCollectionTypeOneCell"];
- [self.collectionView registerNib:[UINib nibWithNibName:@"VipLessonCollectionTypeTwoCell" bundle:nil] forCellWithReuseIdentifier:@"VipLessonCollectionTypeTwoCell"];
- [self.collectionView registerNib:[UINib nibWithNibName:@"VipLessonCollectionTypeThreeCell" bundle:nil] forCellWithReuseIdentifier:@"VipLessonCollectionTypeThreeCell"];
- [self.collectionView registerNib:[UINib nibWithNibName:@"VipLessonCollectionReusableView" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"VipLessonCollectionReusableView"];
- }
- #pragma mark - UICollectionViewDelegate, UICollectionViewDataSource
- - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
- return 3;
- }
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
- switch (section) {
- case 0:
- return 1;
- case 1:
- return 3;
- case 2:
- return 2;
-
- default:
- return 0;
- }
- }
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
- switch (indexPath.section) {
- case 0:
- return CGSizeMake(kScreenWidth - (8 * 2), (kScreenWidth - (8 * 2)) * 0.25);
- case 1:
- return CGSizeMake((kScreenWidth - (8 * 4))/3.0, ((kScreenWidth - (8 * 4))/3.0) * (2.0 / 3.0));
- case 2:
- return CGSizeMake((kScreenWidth - (8 * 3))/2.0, (kScreenWidth - (8 * 3))/2.0 * (7.0 / 16.0));
-
- default:
- return CGSizeZero;
- }
- }
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
- return CGSizeMake(kScreenWidth, 50);
- }
- - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
- if (kind == UICollectionElementKindSectionHeader) {
- VipLessonCollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"VipLessonCollectionReusableView" forIndexPath:indexPath];
- headerView.rightTitleLabel.text = self.headerTitlesArr[indexPath.section];
- return headerView;
- } else {
- return nil;
- }
- }
- - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
- switch (indexPath.section) {
- case 0: {
- VipLessonCollectionTypeOneCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"VipLessonCollectionTypeOneCell" forIndexPath:indexPath];
- return cell;
- }
- case 1: {
- VipLessonCollectionTypeTwoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"VipLessonCollectionTypeTwoCell" forIndexPath:indexPath];
- cell.imageView.image = [UIImage imageNamed:self.secTwoImagesArr[indexPath.row]];
- cell.titleLabel.text = self.secTwoTitlesArr[indexPath.row];
- return cell;
- }
- case 2: {
- VipLessonCollectionTypeThreeCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"VipLessonCollectionTypeThreeCell" forIndexPath:indexPath];
- cell.imageView.image = [UIImage imageNamed:self.secThreeImagesArr[indexPath.row]];
- cell.titleLabel.text = self.secThreeTitlesArr[indexPath.row];
- cell.subTItleLabel.text = self.secThreeSubTitlesArr[indexPath.row];
- return cell;
- }
-
- default:
- return nil;
- }
- }
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
- [collectionView deselectItemAtIndexPath:indexPath animated:YES];
- VipExamViewController *vc = [[VipExamViewController alloc] init];
- [self navPushHideTabbarToVC:vc];
- }
- /// collectinView section header 在高版本存在系统BUG,需要设置zPosition = 0.0
- - (void)collectionView:(UICollectionView *)collectionView willDisplaySupplementaryView:(UICollectionReusableView *)view forElementKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)indexPath {
- view.layer.zPosition = 0.0;
- }
- #pragma mark - Lazy Load
- - (UICollectionView *)collectionView {
- if (!_collectionView) {
- UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
- layout.itemSize = CGSizeMake(100, 100);
- layout.sectionInset = UIEdgeInsetsMake(0, 8, 0, 8);
- layout.minimumLineSpacing = 8;
- layout.minimumInteritemSpacing = 8;
- _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) collectionViewLayout:layout];
- _collectionView.dataSource = self;
- _collectionView.delegate = self;
- _collectionView.backgroundColor = [UIColor whiteColor];
- }
- return _collectionView;
- }
- - (NSArray *)headerTitlesArr {
- return @[@"01 速成课程", @"02 秒懂技巧", @"03 精选课程"];
- }
- - (NSArray *)secTwoImagesArr {
- return @[@"fast_voice_icon", @"fast_video_icon", @"fast_class_icon"];
- }
- - (NSArray *)secTwoTitlesArr {
- return @[@"语音技巧", @"视频技巧", @"考点归类速记"];
- }
- - (NSArray *)secThreeImagesArr {
- return @[@"threeDay", @"errorTopic"];
- }
- - (NSArray *)secThreeTitlesArr {
- return @[@"三天特训", @"易错题"];
- }
- - (NSArray *)secThreeSubTitlesArr {
- return @[@"冲刺100分", @"攻克难点"];
- }
- @end
|