YOUPAIMineInfoPhotoCell.m 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. //
  2. // YOUPAIMinePhotoCell.m
  3. // MSYOUPAI
  4. //
  5. // Created by admin on 2022/3/2.
  6. // Copyright © 2022 MS. All rights reserved.
  7. //
  8. #import "YOUPAIMineInfoPhotoCell.h"
  9. #import "UIView+Category.h"
  10. #import "YOUPAILCUserShowModel.h"
  11. @implementation YOUPAIMineInfoPhotoCell{
  12. UILongPressGestureRecognizer *longPress;
  13. }
  14. +(CGFloat)itemwidth{
  15. return (KScreenWidth-24-16)/3;
  16. }
  17. +(CGFloat)cellheight{
  18. return (YOUPAIMineInfoPhotoCell.itemwidth*2)+8+54+69;
  19. }
  20. -(UICollectionViewFlowLayout *)flowLayout{
  21. if (_flowLayout == nil){
  22. _flowLayout = [UICollectionViewFlowLayout new];
  23. _flowLayout.minimumLineSpacing = 7;
  24. _flowLayout.minimumInteritemSpacing = 7;
  25. CGFloat itemwidth = YOUPAIMineInfoPhotoCell.itemwidth;
  26. _flowLayout.itemSize = CGSizeMake(itemwidth, itemwidth);
  27. _flowLayout.sectionInset = UIEdgeInsetsMake(0, 12, 0, 12);
  28. }
  29. return _flowLayout;
  30. }
  31. -(UICollectionView *)collectionView{
  32. if (_collectionView == nil){
  33. _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:self.flowLayout];
  34. _collectionView.backgroundColor = UIColor.clearColor;
  35. _collectionView.dataSource = self;
  36. _collectionView.delegate = self;
  37. [_collectionView registerClass:[YOUPAIMinePhotoCollectionViewCell class] forCellWithReuseIdentifier:@"YOUPAIMinePhotoCollectionViewCell"];
  38. longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(youpaiflongPressHandel:)];
  39. [self addGestureRecognizer:longPress];
  40. }
  41. return _collectionView;
  42. }
  43. -(UILabel *)remarkLab{
  44. if (_remarkLab == nil){
  45. _remarkLab = [UILabel new];
  46. _remarkLab.numberOfLines = 2;
  47. _remarkLab.textColor = LZA3AABEColor;
  48. _remarkLab.font = LCFont12;
  49. }
  50. return _remarkLab;
  51. }
  52. -(YOUPAIBubbleLabel *)bubbleLab{
  53. if (_bubbleLab == nil){
  54. _bubbleLab = [YOUPAIBubbleLabel new];
  55. _bubbleLab.text = @"上传照片奖励+20钻石";
  56. }
  57. return _bubbleLab;
  58. }
  59. -(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
  60. if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
  61. [self.contentView addSubview:self.collectionView];
  62. [self.contentView addSubview:self.remarkLab];
  63. [self.contentView addSubview:self.bubbleLab];
  64. [self makeLayout];
  65. [self defualUI];
  66. }
  67. return self;
  68. }
  69. -(void)defualUI{
  70. self.titleLab.text = @"展示照片";
  71. self.remarkLab.text = @"1、拖拽相片可以更改排序,单击查看大图可删除相册\n2、照片涉黄或者审核不通过将被删除,严重者冻结账号";
  72. // self.vlaueLab.text = @"去录制";
  73. }
  74. -(void)makeLayout{
  75. [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
  76. make.centerY.mas_equalTo(self.rightArrow);
  77. make.left.mas_equalTo(12);
  78. }];
  79. [self.rightArrow mas_makeConstraints:^(MASConstraintMaker *make) {
  80. make.centerY.mas_equalTo(self.mas_top).offset(27);
  81. make.right.mas_equalTo(-12);
  82. }];
  83. [_collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  84. make.top.mas_equalTo(self).offset(54);
  85. make.left.right.mas_equalTo(self);
  86. make.height.mas_equalTo((YOUPAIMineInfoPhotoCell.itemwidth*2) + 8);
  87. }];
  88. [_remarkLab mas_makeConstraints:^(MASConstraintMaker *make) {
  89. make.height.mas_equalTo(69);
  90. make.left.mas_equalTo(self.titleLab);
  91. make.top.mas_equalTo(self.collectionView.mas_bottom);
  92. }];
  93. [_bubbleLab mas_makeConstraints:^(MASConstraintMaker *make) {
  94. make.left.mas_equalTo(self.titleLab.mas_right).offset(2);
  95. make.centerY.mas_equalTo(self.titleLab);
  96. }];
  97. [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
  98. make.height.mas_equalTo(0.5);
  99. make.centerX.mas_equalTo(0);
  100. make.width.mas_offset(KScreenWidth-30);
  101. }];
  102. }
  103. #pragma mark - 拖拽事件照片处理
  104. - (void)youpaiflongPressHandel:(UILongPressGestureRecognizer*)sender{
  105. if (sender.state == UIGestureRecognizerStateBegan) {
  106. NSIndexPath *selectIndexPath = [_collectionView indexPathForItemAtPoint:[sender locationInView:_collectionView]];
  107. [_collectionView beginInteractiveMovementForItemAtIndexPath:selectIndexPath];
  108. }else if (sender.state == UIGestureRecognizerStateChanged){
  109. [_collectionView updateInteractiveMovementTargetPosition:[sender locationInView:sender.view]];
  110. }else if (sender.state == UIGestureRecognizerStateEnded) {
  111. [_collectionView endInteractiveMovement];
  112. }else{
  113. [_collectionView cancelInteractiveMovement];
  114. }
  115. }
  116. // MARK: delegate
  117. -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  118. return 6;
  119. }
  120. -(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  121. YOUPAIMinePhotoCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"YOUPAIMinePhotoCollectionViewCell" forIndexPath:indexPath];
  122. if (indexPath.row < _youpaipimages.count){
  123. NSString *item = _youpaipimages[indexPath.row];
  124. NSURL *url = [[LCTools getImageUrlWithAddress:item] urlWithImageScale:60];
  125. cell.youpaipImageView.contentMode = UIViewContentModeCenter;
  126. [cell.youpaipImageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"icon_180_up_plus"] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
  127. if(error){
  128. cell.youpaipImageView.contentMode = UIViewContentModeCenter;
  129. }else{
  130. cell.youpaipImageView.contentMode = UIViewContentModeScaleAspectFill;
  131. }
  132. }];
  133. }else{
  134. cell.youpaipImageView.contentMode = UIViewContentModeCenter;
  135. cell.youpaipImageView.image = [UIImage imageNamed:@"icon_180_up_plus"];
  136. }
  137. return cell;
  138. }
  139. -(BOOL)collectionView:(UICollectionView *)collectionView canMoveItemAtIndexPath:(NSIndexPath *)indexPath{
  140. if (indexPath.row>=_youpaipimages.count){
  141. return false;
  142. }
  143. return true;
  144. }
  145. - (void)collectionView:(UICollectionView *)collectionView moveItemAtIndexPath:(nonnull NSIndexPath *)sourceIndexPath toIndexPath:(nonnull NSIndexPath *)destinationIndexPath
  146. {
  147. @weakify(self);
  148. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.35 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  149. @strongify(self);
  150. if (destinationIndexPath.row>=self.youpaipimages.count){
  151. [self.collectionView reloadData];
  152. return;
  153. }
  154. if (sourceIndexPath.row>= self.youpaipimages.count){
  155. [self.collectionView reloadData];
  156. return;
  157. }
  158. [self.youpaipimages exchangeObjectAtIndex:sourceIndexPath.item withObjectAtIndex:destinationIndexPath.item];
  159. [self.collectionView reloadData];
  160. });
  161. }
  162. -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  163. if (_delegate && [_delegate respondsToSelector:@selector(mineInfoPhotoCellhandle:indexpath:)]){
  164. [_delegate mineInfoPhotoCellhandle:self indexpath:indexPath];
  165. }
  166. }
  167. @end
  168. @implementation YOUPAIMinePhotoCollectionViewCell
  169. -(UIImageView *)youpaipImageView{
  170. if (_youpaipImageView == nil){
  171. _youpaipImageView = [UIImageView new];
  172. [_youpaipImageView ms_radius:10];
  173. _youpaipImageView.backgroundColor = LZF7F8FAColor;
  174. _youpaipImageView.image = [UIImage imageNamed:@"icon_180_up_plus"];
  175. _youpaipImageView.contentMode = UIViewContentModeCenter;
  176. }
  177. return _youpaipImageView;
  178. }
  179. -(instancetype)initWithFrame:(CGRect)frame{
  180. if (self == [super initWithFrame:frame]){
  181. [self.contentView addSubview:self.youpaipImageView];
  182. [self makeLayout];
  183. }
  184. return self;
  185. }
  186. -(void)makeLayout{
  187. [_youpaipImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  188. make.left.right.top.bottom.mas_equalTo(0);
  189. }];
  190. }
  191. @end