123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- //
- // imageCollectionViewCell.m
- // Private-X
- //
- // 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;
- @property (strong, nonatomic) UILabel *timeLabel;
- @end
- @implementation imageCollectionViewCell
- - (instancetype)initWithFrame:(CGRect)frame {
- if (self = [super initWithFrame:frame]) {
-
- [self setupSubViews];
- }
- return self;
- }
- - (void)setupSubViews{
- _imageView = [UIImageView new];
- //_imageView.backgroundColor = [UIColor lightGrayColor];
- _imageView.contentMode = UIViewContentModeScaleAspectFill;
- _imageView.layer.masksToBounds = YES;
- [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 = 1; // 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;
-
- _timeLabel = [[UILabel alloc] init];
- _timeLabel.textColor = [UIColor whiteColor];
- _timeLabel.font = [UIFont systemFontOfSize:14.0];
- _timeLabel.textAlignment = NSTextAlignmentRight;
- _timeLabel.hidden = YES;
- [_imageView addSubview:_timeLabel];
-
- [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(5);
- make.right.mas_equalTo(-5);
- make.height.mas_equalTo(20);
- make.bottom.mas_equalTo(-5);
- }];
- }
- - (void)setCurFileModel:(NASFilePicDataArrModel *)curFileModel
- {
- _curFileModel = curFileModel;
-
- NSString *filePath = _curFileModel.path;
- NSString *urlStr = ksharedAppDelegate.NASFileByBoxService;
- NSString *fileUrl = [[NSString alloc] initWithFormat:@"%@getThumbnail?path=%@",urlStr,filePath];
-
- UIImage *defaultImage = [UIImage imageNamed:@"uploadFile_image"];
- if([self.fileType isEqualToString:@"video"])
- {
- _timeLabel.hidden = NO;
- NSInteger curPlayTime = _curFileModel.duration;
- NSInteger hourTime = 60*60;
- NSInteger minTime = 60;
-
- NSString *playTimeStr = nil;
- NSString *playHourTimeStr = nil;
- NSString *playMinTimeStr = nil;
- NSString *playSecondTimeStr = nil;
- if(curPlayTime >= hourTime){
- NSInteger hour = curPlayTime/hourTime;
- playHourTimeStr = [[NSString alloc] initWithFormat:@"%ld",hour];
- curPlayTime = curPlayTime % hourTime;
- }
-
- if(curPlayTime >= minTime){
- NSInteger min = curPlayTime/minTime;
- if(min >=10){
- playMinTimeStr = [[NSString alloc] initWithFormat:@"%ld",min];
- }
- else{
- playMinTimeStr = [[NSString alloc] initWithFormat:@"0%ld",min];
- }
- curPlayTime = curPlayTime % min;
- }
- else{
- playMinTimeStr = @"00";
- }
-
- //秒
- {
- if(curPlayTime >=10){
- playSecondTimeStr = [[NSString alloc] initWithFormat:@"%ld",curPlayTime];
- }
- else{
- playSecondTimeStr = [[NSString alloc] initWithFormat:@"0%ld",curPlayTime];
- }
- }
-
- NSString *totalTimeStr = nil;
- if(playHourTimeStr){
- totalTimeStr = [[NSString alloc] initWithFormat:@"%@:%@:%@",playHourTimeStr,playMinTimeStr,playSecondTimeStr];
- }
- else{
- totalTimeStr = [[NSString alloc] initWithFormat:@"%@:%@",playMinTimeStr,playSecondTimeStr];
- }
-
-
- NSShadow *shadow = [[NSShadow alloc] init];
- shadow.shadowBlurRadius = 4;
- shadow.shadowColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.5];
- shadow.shadowOffset =CGSizeMake(0,2);
-
- NSAttributedString * attributedText = [[NSAttributedString alloc] initWithString:totalTimeStr attributes:@{NSShadowAttributeName:shadow}];
- _timeLabel.attributedText = attributedText;
-
-
- defaultImage = [UIImage imageNamed:@"uploadFile_Video"];
- }
- else{
- //iOS格式的图片 代理拿不到缩略图
- if([filePath rangeOfString:@".HEIC"].location != NSNotFound
- ||[filePath rangeOfString:@".heic"].location != NSNotFound){
- fileUrl = [[NSString alloc] initWithFormat:@"%@getFile?path=%@",urlStr,filePath];
- }
- _timeLabel.hidden = YES;
- }
- fileUrl = [fileUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
-
- [_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;
- // }
-
- 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
|