// // imageCollectionViewCell.m // 双子星云手机 // // Created by xd h on 2024/5/13. // #import "imageCollectionViewCell.h" @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:(couldPhoneFileModel *)curFileModel { _curFileModel = curFileModel; //[[downloadThumbnailManager shareInstance] handlToDownloadThumbnailInDownTableViewWith:@[_curFileModel]]; _imageView.image = [UIImage imageNamed:@"uploadFile_image"]; if([curFileModel.fileType isEqualToString:@"video"]) { _imageView.image = [UIImage imageNamed:@"uploadFile_Video"]; } NSString *fileName = [_curFileModel getFileNameFun]; NSString*pathStr = [cachesFileManager getFilePathWithName:fileName type:DownLoadThumbnail]; UIImage *curImage = [UIImage imageWithContentsOfFile:pathStr]; if(curImage){ _imageView.image = curImage; } 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