ZFTableViewCell.m 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. //
  2. // ZFTableViewCell.m
  3. // ZFPlayer
  4. //
  5. // Created by 紫枫 on 2018/4/3.
  6. // Copyright © 2018年 紫枫. All rights reserved.
  7. //
  8. #import "ZFTableViewCell.h"
  9. #import <ZFPlayer/UIImageView+ZFCache.h>
  10. @interface ZFTableViewCell ()
  11. @property (nonatomic, strong) UIImageView *headImageView;
  12. @property (nonatomic, strong) UILabel *nickNameLabel;
  13. @property (nonatomic, strong) UIImageView *coverImageView;
  14. @property (nonatomic, strong) UIView *fullMaskView;
  15. @property (nonatomic, strong) UIButton *playBtn;
  16. @property (nonatomic, strong) UILabel *titleLabel;
  17. @property (nonatomic, weak) id<ZFTableViewCellDelegate> delegate;
  18. @property (nonatomic, strong) NSIndexPath *indexPath;
  19. @property (nonatomic, strong) UIImageView *bgImgView;
  20. @property (nonatomic, strong) UIView *effectView;
  21. @property (nonatomic, strong) UITapGestureRecognizer *tapGesture;
  22. @end
  23. @implementation ZFTableViewCell
  24. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  25. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  26. if (self) {
  27. [self.contentView addSubview:self.headImageView];
  28. [self.contentView addSubview:self.nickNameLabel];
  29. [self.contentView addSubview:self.bgImgView];
  30. [self.bgImgView addSubview:self.effectView];
  31. [self.contentView addSubview:self.coverImageView];
  32. [self.coverImageView addSubview:self.playBtn];
  33. [self.contentView addSubview:self.titleLabel];
  34. [self.contentView addSubview:self.fullMaskView];
  35. self.contentView.backgroundColor = [UIColor blackColor];
  36. self.selectionStyle = UITableViewCellSelectionStyleNone;
  37. [self.coverImageView addGestureRecognizer:self.tapGesture];
  38. }
  39. return self;
  40. }
  41. - (void)setLayout:(ZFTableViewCellLayout *)layout {
  42. _layout = layout;
  43. self.headImageView.frame = layout.headerRect;
  44. self.nickNameLabel.frame = layout.nickNameRect;
  45. self.coverImageView.frame = layout.videoRect;
  46. self.bgImgView.frame = layout.videoRect;
  47. self.effectView.frame = self.bgImgView.bounds;
  48. self.titleLabel.frame = layout.titleLabelRect;
  49. self.playBtn.frame = layout.playBtnRect;
  50. self.fullMaskView.frame = layout.maskViewRect;
  51. [self.headImageView setImageWithURLString:layout.data.head placeholder:[UIImage imageNamed:@"defaultUserIcon"]];
  52. [self.coverImageView setImageWithURLString:layout.data.thumbnail_url placeholder:[UIImage imageNamed:@"loading_bgView"]];
  53. [self.bgImgView setImageWithURLString:layout.data.thumbnail_url placeholder:[UIImage imageNamed:@"loading_bgView"]];
  54. self.nickNameLabel.text = layout.data.nick_name;
  55. self.titleLabel.text = layout.data.title;
  56. }
  57. - (void)setDelegate:(id<ZFTableViewCellDelegate>)delegate withIndexPath:(NSIndexPath *)indexPath {
  58. self.delegate = delegate;
  59. self.indexPath = indexPath;
  60. }
  61. - (void)setNormalMode {
  62. self.fullMaskView.hidden = YES;
  63. self.titleLabel.textColor = [UIColor blackColor];
  64. self.nickNameLabel.textColor = [UIColor blackColor];
  65. self.contentView.backgroundColor = [UIColor whiteColor];
  66. }
  67. - (void)showMaskView {
  68. [UIView animateWithDuration:0.3 animations:^{
  69. self.fullMaskView.alpha = 1;
  70. }];
  71. }
  72. - (void)hideMaskView {
  73. [UIView animateWithDuration:0.3 animations:^{
  74. self.fullMaskView.alpha = 0;
  75. }];
  76. }
  77. - (void)playClick {
  78. if ([self.delegate respondsToSelector:@selector(zf_playTheVideoAtIndexPath:)]) {
  79. [self.delegate zf_playTheVideoAtIndexPath:self.indexPath];
  80. }
  81. }
  82. #pragma mark - getter
  83. - (UIButton *)playBtn {
  84. if (!_playBtn) {
  85. _playBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  86. [_playBtn setImage:[UIImage imageNamed:@"new_allPlay_44x44_"] forState:UIControlStateNormal];
  87. [_playBtn addTarget:self action:@selector(playClick) forControlEvents:UIControlEventTouchUpInside];
  88. }
  89. return _playBtn;
  90. }
  91. - (UIView *)fullMaskView {
  92. if (!_fullMaskView) {
  93. _fullMaskView = [UIView new];
  94. _fullMaskView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.8];
  95. _fullMaskView.userInteractionEnabled = NO;
  96. }
  97. return _fullMaskView;
  98. }
  99. - (UILabel *)titleLabel {
  100. if (!_titleLabel) {
  101. _titleLabel = [UILabel new];
  102. _titleLabel.textColor = [UIColor whiteColor];
  103. _titleLabel.numberOfLines = 0;
  104. _titleLabel.font = [UIFont systemFontOfSize:15];
  105. }
  106. return _titleLabel;
  107. }
  108. - (UILabel *)nickNameLabel {
  109. if (!_nickNameLabel) {
  110. _nickNameLabel = [UILabel new];
  111. _nickNameLabel.textColor = [UIColor whiteColor];
  112. _nickNameLabel.font = [UIFont systemFontOfSize:15];
  113. }
  114. return _nickNameLabel;
  115. }
  116. - (UIImageView *)headImageView {
  117. if (!_headImageView) {
  118. _headImageView = [[UIImageView alloc] init];
  119. _headImageView.userInteractionEnabled = YES;
  120. }
  121. return _headImageView;
  122. }
  123. - (UIImageView *)coverImageView {
  124. if (!_coverImageView) {
  125. _coverImageView = [[UIImageView alloc] init];
  126. _coverImageView.userInteractionEnabled = YES;
  127. _coverImageView.tag = kPlayerViewTag;
  128. _coverImageView.clipsToBounds = YES;
  129. _coverImageView.contentMode = UIViewContentModeScaleAspectFit;
  130. }
  131. return _coverImageView;
  132. }
  133. - (UIImageView *)bgImgView {
  134. if (!_bgImgView) {
  135. _bgImgView = [[UIImageView alloc] init];
  136. _bgImgView.userInteractionEnabled = YES;
  137. }
  138. return _bgImgView;
  139. }
  140. - (UIView *)effectView {
  141. if (!_effectView) {
  142. if (@available(iOS 8.0, *)) {
  143. UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
  144. _effectView = [[UIVisualEffectView alloc] initWithEffect:effect];
  145. } else {
  146. UIToolbar *effectView = [[UIToolbar alloc] init];
  147. effectView.barStyle = UIBarStyleBlackTranslucent;
  148. _effectView = effectView;
  149. }
  150. }
  151. return _effectView;
  152. }
  153. - (UITapGestureRecognizer *)tapGesture {
  154. if (!_tapGesture) {
  155. _tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(playClick)];
  156. }
  157. return _tapGesture;
  158. }
  159. @end