JLRecommendFacePackgeViewController.m 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. //
  2. // JLRecommendFacePackgeViewController.m
  3. // shiku_im
  4. //
  5. // Created by JayLuo on 2019/12/11.
  6. // Copyright © 2019 Reese. All rights reserved.
  7. //
  8. #import "JLRecommendFacePackgeViewController.h"
  9. #import "JLFacePackgeViewCell.h"
  10. #import "JLFacePackgeViewHeader.h"
  11. #import "JLFacePackgeModel.h"
  12. #import "JLFacePackgeDetailViewController.h"
  13. #import "JLRecommendFacePackgeViewController.h"
  14. #define cellID @"JLFacePackgeViewCell"
  15. @interface JLRecommendFacePackgeViewController ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>
  16. @property (nonatomic, strong) UICollectionView *collectionView;
  17. @property (nonatomic, strong) NSMutableArray *facePackages;
  18. @end
  19. @implementation JLRecommendFacePackgeViewController
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. // Do any additional setup after loading the view.
  23. self.isGotoBack = YES;
  24. self.title = @"新品推荐";
  25. self.heightFooter = 0;
  26. self.heightHeader = JX_SCREEN_TOP;
  27. [self createHeadAndFoot];
  28. _facePackages = [NSMutableArray array];
  29. //0 新品排行 1热门推荐
  30. [g_server getFaceList:@"1" View:self];
  31. [self setupUI];
  32. }
  33. - (void)setupUI {
  34. [self collectionView];
  35. }
  36. - (void)didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
  37. if([aDownload.action isEqualToString:act_FaceList]){
  38. _facePackages = [JLFacePackgeModel mj_objectArrayWithKeyValuesArray:array1];
  39. [self.collectionView reloadData];
  40. }
  41. }
  42. - (UICollectionView *)collectionView {
  43. if (_collectionView == nil) {
  44. UICollectionViewFlowLayout *layout = ({
  45. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  46. // 设置尺寸
  47. CGFloat width = (self_width - 6 * 10)/3;
  48. layout.itemSize = CGSizeMake(width, width * 4 / 3);
  49. //估算的尺寸(一般不需要设置)
  50. // layout.estimatedItemSize = CGSizeMake(120, 130);
  51. //头部的参考尺寸(就是尺寸)
  52. // layout.headerReferenceSize = CGSizeMake(self_width, 50);
  53. //尾部的参考尺寸
  54. layout.footerReferenceSize = CGSizeMake(100, 100);
  55. layout.sectionFootersPinToVisibleBounds = YES;
  56. layout.sectionHeadersPinToVisibleBounds = YES;
  57. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  58. layout.scrollDirection = UICollectionViewScrollDirectionVertical;
  59. layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
  60. layout.minimumInteritemSpacing = 10;
  61. layout.minimumLineSpacing = 10;
  62. layout;
  63. });
  64. _collectionView = ({
  65. UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  66. collectionView.bounds = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
  67. collectionView.backgroundColor = [UIColor clearColor];
  68. collectionView.frame = CGRectMake(0, JX_SCREEN_TOP, self.view.bounds.size.width, self.view.bounds.size.height-JX_SCREEN_TOP);
  69. collectionView.dataSource = self;
  70. collectionView.delegate = self;
  71. [collectionView registerNib:[UINib nibWithNibName:@"JLFacePackgeViewCell" bundle:nil] forCellWithReuseIdentifier:cellID];
  72. [collectionView registerNib:[UINib nibWithNibName:@"JLFacePackgeViewHeader" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"JLFacePackgeViewHeaderID"];
  73. //设置滚动条
  74. collectionView.showsHorizontalScrollIndicator = NO;
  75. collectionView.showsVerticalScrollIndicator = YES;
  76. //设置是否需要弹簧效果
  77. collectionView.bounces = NO;
  78. collectionView;
  79. });
  80. [self.view addSubview:_collectionView];
  81. }
  82. return _collectionView;
  83. }
  84. #pragma mark - UICollectionViewDataSource
  85. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  86. return 1;
  87. }
  88. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  89. return _facePackages.count;
  90. }
  91. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  92. JLFacePackgeViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
  93. cell.model = _facePackages[indexPath.row];
  94. return cell;
  95. }
  96. - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
  97. return UIEdgeInsetsMake(5, 10, 5, 10);
  98. }
  99. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
  100. UICollectionReusableView *headerView = nil;
  101. if ([kind isEqualToString:UICollectionElementKindSectionHeader]){
  102. JLFacePackgeViewHeader *view = (JLFacePackgeViewHeader *) [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"JLFacePackgeViewHeaderID" forIndexPath:indexPath];
  103. headerView = view;
  104. }
  105. return headerView;
  106. }
  107. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
  108. return CGSizeMake(self_width, 0.5);
  109. }
  110. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section {
  111. return CGSizeZero;
  112. }
  113. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  114. JLFacePackgeModel *model = _facePackages[indexPath.row];
  115. JLFacePackgeDetailViewController *vc = [[JLFacePackgeDetailViewController alloc] init];
  116. vc.model = model;
  117. [g_navigation pushViewController:vc animated:YES];
  118. }
  119. @end