imageCollectionViewCell.m 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. //
  2. // imageCollectionViewCell.m
  3. // 双子星云手机
  4. //
  5. // Created by xd h on 2024/5/13.
  6. //
  7. #import "imageCollectionViewCell.h"
  8. #import <SDWebImage/SDWebImage.h>
  9. @interface imageCollectionViewCell()
  10. @property (strong, nonatomic) UIImageView *imageView;
  11. @property (nonatomic, strong) UIButton *selectButton;
  12. @end
  13. @implementation imageCollectionViewCell
  14. - (instancetype)initWithFrame:(CGRect)frame {
  15. if (self = [super initWithFrame:frame]) {
  16. [self setupSubViews];
  17. }
  18. return self;
  19. }
  20. - (void)setupSubViews{
  21. _imageView = [UIImageView new];
  22. [self.contentView addSubview:_imageView];
  23. [_imageView mas_makeConstraints:^(MASConstraintMaker *make) {
  24. make.left.mas_equalTo(0);
  25. make.right.mas_equalTo(0);
  26. make.top.mas_equalTo(0);
  27. make.bottom.mas_equalTo(0);
  28. }];
  29. _imageView.userInteractionEnabled = YES;
  30. // 创建长按手势识别器
  31. UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];
  32. // 设置长按手势的最小按压时间
  33. longPress.minimumPressDuration = 2; // 2秒
  34. // 将手势识别器添加到视图上
  35. [_imageView addGestureRecognizer:longPress];
  36. UIButton *but = [[UIButton alloc] init];
  37. [but setImage:[UIImage imageNamed:@"upload_file_uncheck2"] forState:UIControlStateNormal];
  38. [but setImage:[UIImage imageNamed:@"upload_file_check"] forState:UIControlStateSelected];
  39. [self.contentView addSubview:but];
  40. [but addTarget:self action:@selector(didClickButFun:) forControlEvents:UIControlEventTouchUpInside];
  41. but.hidden = YES;
  42. //but.backgroundColor = [UIColor greenColor];
  43. [but mas_makeConstraints:^(MASConstraintMaker *make) {
  44. make.width.mas_equalTo(30);
  45. make.height.mas_equalTo(30);
  46. make.right.mas_equalTo(0);
  47. make.top.mas_equalTo(0);
  48. }];
  49. self.selectButton = but;
  50. }
  51. - (void)setCurFileModel:(NASFilePicDataArrModel *)curFileModel
  52. {
  53. _curFileModel = curFileModel;
  54. UIImage *defaultImage = [UIImage imageNamed:@"uploadFile_image"];
  55. if([self.fileType isEqualToString:@"video"])
  56. {
  57. defaultImage = [UIImage imageNamed:@"uploadFile_Video"];
  58. _imageView.image = defaultImage;
  59. }
  60. else{
  61. NSString *filePath = _curFileModel.path;
  62. NSString *urlStr = ksharedAppDelegate.NASFileService;
  63. NSString *fileUrl = [[NSString alloc] initWithFormat:@"%@getThumbnail?path=%@",urlStr,filePath];
  64. //iOS格式的图片 代理拿不到缩略图
  65. if([filePath rangeOfString:@".HEIC"].location != NSNotFound
  66. ||[filePath rangeOfString:@".heic"].location != NSNotFound){
  67. fileUrl = [[NSString alloc] initWithFormat:@"%@getFile?path=%@",urlStr,filePath];
  68. }
  69. [_imageView sd_setImageWithURL:[NSURL URLWithString:fileUrl] placeholderImage:defaultImage completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
  70. // if(image){
  71. // HLog(@"11图片1:%@",imageURL.absoluteString);
  72. // }
  73. // else{
  74. // HLog(@"11图片0:%@",imageURL.absoluteString);
  75. // }
  76. }];
  77. }
  78. if(!_isEditType){
  79. self.selectButton.hidden = YES;
  80. }
  81. else{
  82. self.selectButton.hidden = NO;
  83. self.selectButton.selected = curFileModel.isSelectType;
  84. }
  85. }
  86. #pragma mark 选中按钮
  87. - (void)didClickButFun:(UIButton*)but
  88. {
  89. but.selected = !but.selected;
  90. if(_didClckSelectBut){
  91. _didClckSelectBut(but.selected);
  92. }
  93. }
  94. - (void)longPress:(UILongPressGestureRecognizer *)gesture {
  95. if (gesture.state == UIGestureRecognizerStateBegan) {
  96. HLog(@"长按手势开始");
  97. if(_didClickEditType && !_isEditType){
  98. _didClickEditType(YES);
  99. }
  100. }
  101. }
  102. @end