imageCollectionViewCell.m 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. HLog(@"111");
  66. }];
  67. }
  68. if(!_isEditType){
  69. self.selectButton.hidden = YES;
  70. }
  71. else{
  72. self.selectButton.hidden = NO;
  73. self.selectButton.selected = curFileModel.isSelectType;
  74. }
  75. }
  76. #pragma mark 选中按钮
  77. - (void)didClickButFun:(UIButton*)but
  78. {
  79. but.selected = !but.selected;
  80. if(_didClckSelectBut){
  81. _didClckSelectBut(but.selected);
  82. }
  83. }
  84. - (void)longPress:(UILongPressGestureRecognizer *)gesture {
  85. if (gesture.state == UIGestureRecognizerStateBegan) {
  86. HLog(@"长按手势开始");
  87. if(_didClickEditType && !_isEditType){
  88. _didClickEditType(YES);
  89. }
  90. }
  91. }
  92. @end