YOUPAIBrowserPhotoCell.m 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //
  2. // XGBrowserPhotoCell.m
  3. // XGAPP
  4. //
  5. // Created by 肖浩然的mac on 2020/12/17.
  6. //
  7. #import "YOUPAIBrowserPhotoCell.h"
  8. #import "UIView+NTES.h"
  9. #import "TZImagePickerController.h"
  10. @implementation YOUPAIBrowserPhotoCell
  11. - (instancetype)initWithFrame:(CGRect)frame {
  12. self = [super initWithFrame:frame];
  13. if (self) {
  14. [self setupUI];
  15. }
  16. return self;
  17. }
  18. -(void)setupUI{
  19. self.backgroundColor = [UIColor whiteColor];
  20. _imageView = [[UIImageView alloc] init];
  21. _imageView.backgroundColor = [UIColor colorWithWhite:1.000 alpha:0.500];
  22. _imageView.contentMode = UIViewContentModeScaleAspectFill;
  23. [self.contentView addSubview:_imageView];
  24. [_imageView mas_makeConstraints:^(MASConstraintMaker *make) {
  25. make.edges.mas_equalTo(0);
  26. }];
  27. _imageView.layer.cornerRadius = 8;
  28. _imageView.layer.masksToBounds = YES;
  29. _deleteBtn = [UIButton new];
  30. [self.contentView addSubview:_deleteBtn];
  31. [_deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  32. make.right.mas_equalTo(0);
  33. make.top.mas_equalTo(0);
  34. make.size.mas_equalTo(CGSizeMake(15, 15));
  35. }];
  36. [_deleteBtn setImage:[UIImage imageNamed:@"vqu_images_photo_delete"] forState:UIControlStateNormal];
  37. }
  38. - (void)setAsset:(PHAsset *)asset {
  39. _asset = asset;
  40. _videoImageView.hidden = asset.mediaType != PHAssetMediaTypeVideo;
  41. _gifLable.hidden = ![[asset valueForKey:@"filename"] containsString:@"GIF"];
  42. }
  43. - (void)setRow:(NSInteger)row {
  44. _row = row;
  45. _deleteBtn.tag = row;
  46. }
  47. - (UIView *)snapshotView {
  48. UIView *snapshotView = [[UIView alloc]init];
  49. UIView *cellSnapshotView = nil;
  50. if ([self respondsToSelector:@selector(snapshotViewAfterScreenUpdates:)]) {
  51. cellSnapshotView = [self snapshotViewAfterScreenUpdates:NO];
  52. } else {
  53. CGSize size = CGSizeMake(self.bounds.size.width + 20, self.bounds.size.height + 20);
  54. UIGraphicsBeginImageContextWithOptions(size, self.opaque, 0);
  55. [self.layer renderInContext:UIGraphicsGetCurrentContext()];
  56. UIImage * cellSnapshotImage = UIGraphicsGetImageFromCurrentImageContext();
  57. UIGraphicsEndImageContext();
  58. cellSnapshotView = [[UIImageView alloc]initWithImage:cellSnapshotImage];
  59. }
  60. snapshotView.frame = CGRectMake(0, 0, cellSnapshotView.frame.size.width, cellSnapshotView.frame.size.height);
  61. cellSnapshotView.frame = CGRectMake(0, 0, cellSnapshotView.frame.size.width, cellSnapshotView.frame.size.height);
  62. [snapshotView addSubview:cellSnapshotView];
  63. return snapshotView;
  64. }
  65. @end