JLFacePackgeDetailViewController.m 6.6 KB

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