123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- //
- // imageCollectionViewCell.m
- // 双子星云手机
- //
- // Created by xd h on 2024/5/13.
- //
- #import "imageCollectionViewCell.h"
- #import <SDWebImage/SDWebImage.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:(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];
-
- //iOS格式的图片 代理拿不到缩略图
- if([filePath rangeOfString:@".HEIC"].location != NSNotFound
- ||[filePath rangeOfString:@".heic"].location != NSNotFound){
- fileUrl = [[NSString alloc] initWithFormat:@"%@getFile?path=%@",urlStr,filePath];
- }
-
- [_imageView sd_setImageWithURL:[NSURL URLWithString:fileUrl] placeholderImage:defaultImage completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
- // if(image){
- // HLog(@"11图片1:%@",imageURL.absoluteString);
- // }
- // else{
- // HLog(@"11图片0:%@",imageURL.absoluteString);
- // }
-
- }];
- }
-
- 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
|