ZFDouYinCell.m 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. //
  2. // ZFDouYinCell.m
  3. // ZFPlayer_Example
  4. //
  5. // Created by 紫枫 on 2018/6/4.
  6. // Copyright © 2018年 紫枫. All rights reserved.
  7. //
  8. #import "ZFDouYinCell.h"
  9. #import <ZFPlayer/UIImageView+ZFCache.h>
  10. #import <ZFPlayer/UIView+ZFFrame.h>
  11. #import <ZFPlayer/UIImageView+ZFCache.h>
  12. #import <ZFPlayer/ZFUtilities.h>
  13. #import "ZFLoadingView.h"
  14. @interface ZFDouYinCell ()
  15. @property (nonatomic, strong) UIImageView *coverImageView;
  16. @property (nonatomic, strong) UIButton *likeBtn;
  17. @property (nonatomic, strong) UIButton *commentBtn;
  18. @property (nonatomic, strong) UIButton *shareBtn;
  19. @property (nonatomic, strong) UILabel *titleLabel;
  20. @property (nonatomic, strong) UIImage *placeholderImage;
  21. @property (nonatomic, strong) UIButton *rotation;
  22. @end
  23. @implementation ZFDouYinCell
  24. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  25. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  26. if (self) {
  27. self.selectionStyle = UITableViewCellSelectionStyleNone;
  28. self.contentView.backgroundColor = [UIColor blackColor];
  29. [self.contentView addSubview:self.coverImageView];
  30. [self.contentView addSubview:self.titleLabel];
  31. [self.contentView addSubview:self.likeBtn];
  32. [self.contentView addSubview:self.commentBtn];
  33. [self.contentView addSubview:self.shareBtn];
  34. [self.contentView addSubview:self.rotation];
  35. }
  36. return self;
  37. }
  38. - (void)layoutSubviews {
  39. [super layoutSubviews];
  40. self.coverImageView.frame = self.contentView.bounds;
  41. CGFloat min_x = 0;
  42. CGFloat min_y = 0;
  43. CGFloat min_w = 0;
  44. CGFloat min_h = 0;
  45. CGFloat min_view_w = self.zf_width;
  46. CGFloat min_view_h = self.zf_height;
  47. CGFloat margin = 30;
  48. min_w = 40;
  49. min_h = min_w;
  50. min_x = min_view_w - min_w - 20;
  51. min_y = min_view_h - min_h - 80;
  52. self.shareBtn.frame = CGRectMake(min_x, min_y, min_w, min_h);
  53. min_w = CGRectGetWidth(self.shareBtn.frame);
  54. min_h = min_w;
  55. min_x = CGRectGetMinX(self.shareBtn.frame);
  56. min_y = CGRectGetMinY(self.shareBtn.frame) - min_h - margin;
  57. self.commentBtn.frame = CGRectMake(min_x, min_y, min_w, min_h);
  58. min_w = CGRectGetWidth(self.shareBtn.frame);
  59. min_h = min_w;
  60. min_x = CGRectGetMinX(self.commentBtn.frame);
  61. min_y = CGRectGetMinY(self.commentBtn.frame) - min_h - margin;
  62. self.likeBtn.frame = CGRectMake(min_x, min_y, min_w, min_h);
  63. min_x = 20;
  64. min_h = 20;
  65. min_y = min_view_h - min_h - 50;
  66. min_w = self.likeBtn.zf_left - margin;
  67. self.titleLabel.frame = CGRectMake(min_x, min_y, min_w, min_h);
  68. min_x = 20;
  69. min_w = 50;
  70. min_h = 50;
  71. min_y = (min_view_h - min_h) / 2;
  72. self.rotation.frame = CGRectMake(min_x, min_y, min_w, min_h);
  73. }
  74. #pragma mark - action
  75. - (void)rotationClick {
  76. if ([self.delegate respondsToSelector:@selector(zf_douyinRotation)]) {
  77. [self.delegate zf_douyinRotation];
  78. }
  79. }
  80. #pragma mark - getter
  81. - (UILabel *)titleLabel {
  82. if (!_titleLabel) {
  83. _titleLabel = [UILabel new];
  84. _titleLabel.textColor = [UIColor whiteColor];
  85. _titleLabel.font = [UIFont systemFontOfSize:15];
  86. }
  87. return _titleLabel;
  88. }
  89. - (UIButton *)likeBtn {
  90. if (!_likeBtn) {
  91. _likeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  92. [_likeBtn setImage:[UIImage imageNamed:@"like"] forState:UIControlStateNormal];
  93. }
  94. return _likeBtn;
  95. }
  96. - (UIButton *)commentBtn {
  97. if (!_commentBtn) {
  98. _commentBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  99. [_commentBtn setImage:[UIImage imageNamed:@"comment"] forState:UIControlStateNormal];
  100. }
  101. return _commentBtn;
  102. }
  103. - (UIButton *)shareBtn {
  104. if (!_shareBtn) {
  105. _shareBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  106. [_shareBtn setImage:[UIImage imageNamed:@"share"] forState:UIControlStateNormal];
  107. }
  108. return _shareBtn;
  109. }
  110. - (UIImage *)placeholderImage {
  111. if (!_placeholderImage) {
  112. _placeholderImage = [ZFUtilities imageWithColor:[UIColor colorWithRed:220/255.0 green:220/255.0 blue:220/255.0 alpha:1] size:CGSizeMake(1, 1)];
  113. }
  114. return _placeholderImage;
  115. }
  116. - (void)setData:(ZFTableData *)data {
  117. _data = data;
  118. [self.coverImageView setImageWithURLString:data.thumbnail_url placeholder:[UIImage imageNamed:@"loading_bgView"]];
  119. self.titleLabel.text = data.title;
  120. if (data.video_width > data.video_height) { /// 横屏视频才支持旋转
  121. self.rotation.hidden = NO;
  122. } else {
  123. self.rotation.hidden = YES;
  124. }
  125. }
  126. - (UIImageView *)coverImageView {
  127. if (!_coverImageView) {
  128. _coverImageView = [[UIImageView alloc] init];
  129. _coverImageView.userInteractionEnabled = YES;
  130. _coverImageView.tag = kPlayerViewTag;
  131. _coverImageView.contentMode = UIViewContentModeScaleAspectFit;
  132. }
  133. return _coverImageView;
  134. }
  135. - (UIButton *)rotation {
  136. if (!_rotation) {
  137. _rotation = [UIButton buttonWithType:UIButtonTypeCustom];
  138. [_rotation setImage:[UIImage imageNamed:@"zfplayer_rotaiton"] forState:UIControlStateNormal];
  139. [_rotation addTarget:self action:@selector(rotationClick) forControlEvents:UIControlEventTouchUpInside];
  140. }
  141. return _rotation;
  142. }
  143. @end