imageCollectionViewCell.m 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. [_imageView sd_setImageWithURL:[NSURL URLWithString:fileUrl] placeholderImage:defaultImage completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
  65. // if(image){
  66. // HLog(@"11图片1:%@",imageURL.absoluteString);
  67. // }
  68. // else{
  69. // HLog(@"11图片0:%@",imageURL.absoluteString);
  70. // }
  71. }];
  72. }
  73. if(!_isEditType){
  74. self.selectButton.hidden = YES;
  75. }
  76. else{
  77. self.selectButton.hidden = NO;
  78. self.selectButton.selected = curFileModel.isSelectType;
  79. }
  80. }
  81. #pragma mark 选中按钮
  82. - (void)didClickButFun:(UIButton*)but
  83. {
  84. but.selected = !but.selected;
  85. if(_didClckSelectBut){
  86. _didClckSelectBut(but.selected);
  87. }
  88. }
  89. - (void)longPress:(UILongPressGestureRecognizer *)gesture {
  90. if (gesture.state == UIGestureRecognizerStateBegan) {
  91. HLog(@"长按手势开始");
  92. if(_didClickEditType && !_isEditType){
  93. _didClickEditType(YES);
  94. }
  95. }
  96. }
  97. @end