RITLPhotosBrowseVideoCell.m 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //
  2. // RITLPhotosBrowseVideoCell.m
  3. // RITLPhotoDemo
  4. //
  5. // Created by YueWen on 2018/4/29.
  6. // Copyright © 2018年 YueWen. All rights reserved.
  7. //
  8. #import "RITLPhotosBrowseVideoCell.h"
  9. #import "UICollectionViewCell+RITLPhotosAsset.h"
  10. #import "NSBundle+RITLPhotos.h"
  11. #import "RITLKit.h"
  12. #import "Masonry.h"
  13. //static NSString *const RITLPhotosBrowseVideoCellVideoImageName = @"RITLPhotos.bundle/ritl_video_play";
  14. @implementation RITLPhotosBrowseVideoCell
  15. - (instancetype)initWithFrame:(CGRect)frame
  16. {
  17. if (self = [super initWithFrame:frame]) {
  18. [self buildViews];
  19. }
  20. return self;
  21. }
  22. - (void)buildViews
  23. {
  24. self.contentView.backgroundColor = UIColor.blackColor;
  25. self.imageView = [[UIImageView alloc]init];
  26. self.imageView.contentMode = UIViewContentModeScaleAspectFit;
  27. [self.contentView addSubview:self.imageView];
  28. [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
  29. make.edges.offset(0);
  30. }];
  31. self.playImageView = ({
  32. UIImageView *imageView = [UIImageView new];
  33. imageView.contentMode = UIViewContentModeScaleAspectFill;
  34. imageView.image = /*RITLPhotosBrowseVideoCellVideoImageName.ritl_image*/NSBundle.ritl_video_play;
  35. imageView;
  36. });
  37. [self.contentView addSubview:self.playImageView];
  38. [self.playImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  39. make.height.width.mas_equalTo(80);
  40. make.center.offset(0);
  41. }];
  42. __weak typeof(self) weak = self;
  43. [self.contentView addTapGestureRecognizerNumberOfTap:1 Handler:^(UIView * _Nonnull view) {
  44. if (!weak.playerLayer) { [weak playerAsset]; return; }//如果是stop,就进行播放
  45. [weak stop];
  46. }];
  47. }
  48. - (void)prepareForReuse
  49. {
  50. if (self.playerLayer.superlayer) {
  51. [self.playerLayer removeFromSuperlayer];
  52. self.playerLayer = nil;
  53. }
  54. }
  55. @end