// // imageCollectionViewCell.m // 双子星云手机 // // Created by xd h on 2024/5/13. // #import "imageCollectionViewCell.h" #import @interface imageCollectionViewCell() @property (strong, nonatomic) UIImageView *imageView; @property (nonatomic, strong) UIButton *selectButton; @end @implementation imageCollectionViewCell - (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { [self setupSubViews]; } return self; } - (void)setupSubViews{ _imageView = [UIImageView new]; [self.contentView addSubview:_imageView]; [_imageView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.top.mas_equalTo(0); make.bottom.mas_equalTo(0); }]; _imageView.userInteractionEnabled = YES; // 创建长按手势识别器 UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)]; // 设置长按手势的最小按压时间 longPress.minimumPressDuration = 2; // 2秒 // 将手势识别器添加到视图上 [_imageView addGestureRecognizer:longPress]; UIButton *but = [[UIButton alloc] init]; [but setImage:[UIImage imageNamed:@"upload_file_uncheck2"] forState:UIControlStateNormal]; [but setImage:[UIImage imageNamed:@"upload_file_check"] forState:UIControlStateSelected]; [self.contentView addSubview:but]; [but addTarget:self action:@selector(didClickButFun:) forControlEvents:UIControlEventTouchUpInside]; but.hidden = YES; //but.backgroundColor = [UIColor greenColor]; [but mas_makeConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo(30); make.height.mas_equalTo(30); make.right.mas_equalTo(0); make.top.mas_equalTo(0); }]; self.selectButton = but; } - (void)setCurFileModel:(NASFilePicDataArrModel *)curFileModel { _curFileModel = curFileModel; UIImage *defaultImage = [UIImage imageNamed:@"uploadFile_image"]; if([self.fileType isEqualToString:@"video"]) { defaultImage = [UIImage imageNamed:@"uploadFile_Video"]; _imageView.image = defaultImage; } else{ NSString *filePath = _curFileModel.path; NSString *urlStr = ksharedAppDelegate.NASFileService; NSString *fileUrl = [[NSString alloc] initWithFormat:@"%@/getThumbnail?path=%@",urlStr,filePath]; [_imageView sd_setImageWithURL:[NSURL URLWithString:fileUrl] placeholderImage:defaultImage completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) { HLog(@"111"); }]; } if(!_isEditType){ self.selectButton.hidden = YES; } else{ self.selectButton.hidden = NO; self.selectButton.selected = curFileModel.isSelectType; } } #pragma mark 选中按钮 - (void)didClickButFun:(UIButton*)but { but.selected = !but.selected; if(_didClckSelectBut){ _didClckSelectBut(but.selected); } } - (void)longPress:(UILongPressGestureRecognizer *)gesture { if (gesture.state == UIGestureRecognizerStateBegan) { HLog(@"长按手势开始"); if(_didClickEditType && !_isEditType){ _didClickEditType(YES); } } } @end