JLMyFacePackgeViewController.m 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. //
  2. // JLMyFacePackgeViewController.m
  3. // shiku_im
  4. //
  5. // Created by JayLuo on 2019/12/11.
  6. // Copyright © 2019 Reese. All rights reserved.
  7. //
  8. #import "JLMyFacePackgeViewController.h"
  9. #import "JLMyFacePackgeCell.h"
  10. #import "JLMyFacePackgeHeader.h"
  11. #import "JLFacePackgeModel.h"
  12. #import "JLFacePackgeDetailViewController.h"
  13. #import "JLRecommendFacePackgeViewController.h"
  14. #import "JLSingleFaceViewController.h"
  15. #define cellID @"JLMyFacePackgeCell"
  16. @interface JLMyFacePackgeViewController ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>
  17. @property (nonatomic, strong) UICollectionView *collectionView;
  18. @property (nonatomic, strong) NSMutableArray *facePackages;
  19. @end
  20. @implementation JLMyFacePackgeViewController
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  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:@"0" View:self];
  31. [g_server faceClollectListType:@"0" View:self];
  32. [self setupUI];
  33. }
  34. - (void)setupUI {
  35. [self collectionView];
  36. }
  37. - (void)didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
  38. if([aDownload.action isEqualToString:act_FaceClollectList]){
  39. _facePackages = [JLFacePackgeModel mj_objectArrayWithKeyValuesArray:array1];
  40. [self.collectionView reloadData];
  41. }
  42. if([aDownload.action isEqualToString:act_FaceClollectDeleteByFaceName]){
  43. // NSLog(@"-------%@-----%@", dict, array1);
  44. [SVProgressHUD setMinimumDismissTimeInterval:2.0];
  45. [SVProgressHUD showSuccessWithStatus:@"移除成功"];
  46. [g_notify postNotificationName:kEmojiRefresh object:nil];
  47. [g_server faceClollectListType:@"0" View:self];
  48. }
  49. }
  50. - (UICollectionView *)collectionView {
  51. if (_collectionView == nil) {
  52. UICollectionViewFlowLayout *layout = ({
  53. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  54. // 设置尺寸
  55. CGFloat width = self_width;
  56. layout.itemSize = CGSizeMake(width, 60);
  57. //估算的尺寸(一般不需要设置)
  58. // layout.estimatedItemSize = CGSizeMake(120, 130);
  59. //头部的参考尺寸(就是尺寸)
  60. // layout.headerReferenceSize = CGSizeMake(self_width, 50);
  61. //尾部的参考尺寸
  62. layout.footerReferenceSize = CGSizeMake(100, 100);
  63. layout.sectionFootersPinToVisibleBounds = YES;
  64. layout.sectionHeadersPinToVisibleBounds = YES;
  65. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  66. layout.scrollDirection = UICollectionViewScrollDirectionVertical;
  67. layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
  68. layout.minimumInteritemSpacing = 10;
  69. layout.minimumLineSpacing = 10;
  70. layout;
  71. });
  72. _collectionView = ({
  73. UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  74. collectionView.bounds = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
  75. collectionView.backgroundColor = [UIColor colorWithRed:240/255.0 green:239/255.0 blue:244/255.0 alpha:1];
  76. collectionView.frame = CGRectMake(0, JX_SCREEN_TOP, self.view.bounds.size.width, self.view.bounds.size.height-JX_SCREEN_TOP);
  77. collectionView.dataSource = self;
  78. collectionView.delegate = self;
  79. [collectionView registerNib:[UINib nibWithNibName:@"JLMyFacePackgeCell" bundle:nil] forCellWithReuseIdentifier:cellID];
  80. [collectionView registerNib:[UINib nibWithNibName:@"JLMyFacePackgeHeader" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"JLMyFacePackgeHeader"];
  81. //设置滚动条
  82. collectionView.showsHorizontalScrollIndicator = NO;
  83. collectionView.showsVerticalScrollIndicator = YES;
  84. //设置是否需要弹簧效果
  85. collectionView.bounces = NO;
  86. collectionView;
  87. });
  88. [self.view addSubview:_collectionView];
  89. }
  90. return _collectionView;
  91. }
  92. #pragma mark - UICollectionViewDataSource
  93. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  94. return 1;
  95. }
  96. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  97. return _facePackages.count;
  98. }
  99. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  100. JLMyFacePackgeCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
  101. cell.model = _facePackages[indexPath.row];
  102. cell.JLMyFacePackgeCellDeleteCallBack = ^(NSString * _Nonnull faceId) {
  103. // 删除表情
  104. [g_server faceClollectDeleteByFaceName:faceId View:self];
  105. };
  106. return cell;
  107. }
  108. - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
  109. return UIEdgeInsetsMake(5, 10, 5, 10);
  110. }
  111. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
  112. UICollectionReusableView *headerView = nil;
  113. if ([kind isEqualToString:UICollectionElementKindSectionHeader]){
  114. JLMyFacePackgeHeader *view = (JLMyFacePackgeHeader *) [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"JLMyFacePackgeHeader" forIndexPath:indexPath];
  115. view.JLMyFacePackgeHeaderCallBack = ^{
  116. JLSingleFaceViewController *vc = [[JLSingleFaceViewController alloc] init];
  117. [g_navigation pushViewController:vc animated:YES];
  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, 90);
  125. }
  126. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section {
  127. return CGSizeZero;
  128. }
  129. //- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  130. // JLFacePackgeModel *model = _facePackages[indexPath.row];
  131. // JLFacePackgeDetailViewController *vc = [[JLFacePackgeDetailViewController alloc] init];
  132. // vc.model = model;
  133. // [g_navigation pushViewController:vc animated:YES];
  134. //}
  135. @end