imageCollectionViewCell.m 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. //
  2. // imageCollectionViewCell.m
  3. // 双子星云手机
  4. //
  5. // Created by xd h on 2024/5/13.
  6. //
  7. #import "imageCollectionViewCell.h"
  8. @interface imageCollectionViewCell()
  9. @property (strong, nonatomic) UIImageView *imageView;
  10. @property (nonatomic, strong) UIButton *selectButton;
  11. @end
  12. @implementation imageCollectionViewCell
  13. - (instancetype)initWithFrame:(CGRect)frame {
  14. if (self = [super initWithFrame:frame]) {
  15. [self setupSubViews];
  16. }
  17. return self;
  18. }
  19. - (void)setupSubViews{
  20. _imageView = [UIImageView new];
  21. [self.contentView addSubview:_imageView];
  22. [_imageView mas_makeConstraints:^(MASConstraintMaker *make) {
  23. make.left.mas_equalTo(0);
  24. make.right.mas_equalTo(0);
  25. make.top.mas_equalTo(0);
  26. make.bottom.mas_equalTo(0);
  27. }];
  28. _imageView.userInteractionEnabled = YES;
  29. // 创建长按手势识别器
  30. UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];
  31. // 设置长按手势的最小按压时间
  32. longPress.minimumPressDuration = 2; // 2秒
  33. // 将手势识别器添加到视图上
  34. [_imageView addGestureRecognizer:longPress];
  35. UIButton *but = [[UIButton alloc] init];
  36. [but setImage:[UIImage imageNamed:@"upload_file_uncheck2"] forState:UIControlStateNormal];
  37. [but setImage:[UIImage imageNamed:@"upload_file_check"] forState:UIControlStateSelected];
  38. [self.contentView addSubview:but];
  39. [but addTarget:self action:@selector(didClickButFun:) forControlEvents:UIControlEventTouchUpInside];
  40. but.hidden = YES;
  41. //but.backgroundColor = [UIColor greenColor];
  42. [but mas_makeConstraints:^(MASConstraintMaker *make) {
  43. make.width.mas_equalTo(30);
  44. make.height.mas_equalTo(30);
  45. make.right.mas_equalTo(0);
  46. make.top.mas_equalTo(0);
  47. }];
  48. self.selectButton = but;
  49. }
  50. - (void)setCurFileModel:(couldPhoneFileModel *)curFileModel
  51. {
  52. _curFileModel = curFileModel;
  53. //[[downloadThumbnailManager shareInstance] handlToDownloadThumbnailInDownTableViewWith:@[_curFileModel]];
  54. _imageView.image = [UIImage imageNamed:@"uploadFile_image"];
  55. if([curFileModel.fileType isEqualToString:@"video"])
  56. {
  57. _imageView.image = [UIImage imageNamed:@"uploadFile_Video"];
  58. }
  59. NSString *fileName = [_curFileModel getFileNameFun];
  60. NSString*pathStr = [cachesFileManager getFilePathWithName:fileName type:DownLoadThumbnail];
  61. UIImage *curImage = [UIImage imageWithContentsOfFile:pathStr];
  62. if(curImage){
  63. _imageView.image = curImage;
  64. }
  65. if(!_isEditType){
  66. self.selectButton.hidden = YES;
  67. }
  68. else{
  69. self.selectButton.hidden = NO;
  70. self.selectButton.selected = curFileModel.isSelectType;
  71. }
  72. }
  73. #pragma mark 选中按钮
  74. - (void)didClickButFun:(UIButton*)but
  75. {
  76. but.selected = !but.selected;
  77. if(_didClckSelectBut){
  78. _didClckSelectBut(but.selected);
  79. }
  80. }
  81. - (void)longPress:(UILongPressGestureRecognizer *)gesture {
  82. if (gesture.state == UIGestureRecognizerStateBegan) {
  83. HLog(@"长按手势开始");
  84. if(_didClickEditType && !_isEditType){
  85. _didClickEditType(YES);
  86. }
  87. }
  88. }
  89. @end