CYFacePackageViewController.m 7.2 KB

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