HomeHotTalentCell.m 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. //
  2. // HomeHotTalentCell.m
  3. // KulexiuForStudent
  4. //
  5. // Created by 王智 on 2022/8/29.
  6. //
  7. #import "HomeHotTalentCell.h"
  8. #import <Lottie/Lottie.h>
  9. @interface HomeHotTalentCell ()
  10. @property (weak, nonatomic) IBOutlet UIImageView *teacherAvatar;
  11. @property (weak, nonatomic) IBOutlet UILabel *teacherName;
  12. @property (weak, nonatomic) IBOutlet UILabel *graduateSchool;
  13. @property (weak, nonatomic) IBOutlet UIView *liveView;
  14. @property (weak, nonatomic) IBOutlet UIView *liveColorView;
  15. @property (weak, nonatomic) IBOutlet UILabel *tipsLabel;
  16. @property (weak, nonatomic) IBOutlet UIView *animationBgView;
  17. @property (nonatomic, strong) LOTAnimationView *animationView;
  18. @property (nonatomic, copy) FollowTalentAction callback;
  19. @property (nonatomic, strong) TalentTeacherModel *sourceModel;
  20. @end
  21. @implementation HomeHotTalentCell
  22. - (void)awakeFromNib {
  23. [super awakeFromNib];
  24. // Initialization code
  25. CAGradientLayer *layer = [self createGradientLayerFromColor:HexRGB(0xFF8B39) startPoint:CGPointMake(0.83, 0.55) endColor:HexRGB(0xFF4046) endPoint:CGPointMake(0.14, 1) bounds:self.liveColorView.bounds];
  26. layer.cornerRadius = 7.0f;
  27. layer.masksToBounds = YES;
  28. [self.liveColorView.layer addSublayer:layer];
  29. [self.liveColorView bringSubviewToFront:self.tipsLabel];
  30. if (![self.animationBgView.subviews containsObject:self.animationView]) {
  31. [self.animationBgView addSubview:self.animationView];
  32. [self.animationView mas_makeConstraints:^(MASConstraintMaker *make) {
  33. make.left.right.top.bottom.mas_equalTo(self.animationBgView);
  34. }];
  35. }
  36. }
  37. - (CAGradientLayer *)createGradientLayerFromColor:(UIColor *)fromColor startPoint:(CGPoint)startPoint endColor:(UIColor *)endColor endPoint:(CGPoint)endPoint bounds:(CGRect)bounds {
  38. CAGradientLayer *gradientLayer = [CAGradientLayer layer];
  39. gradientLayer.colors = @[(__bridge id)fromColor.CGColor, (__bridge id)endColor.CGColor];
  40. gradientLayer.startPoint = startPoint;
  41. gradientLayer.endPoint = endPoint;
  42. gradientLayer.frame = bounds;
  43. gradientLayer.locations = @[@(0),@(1.0f)];
  44. return gradientLayer;
  45. }
  46. - (void)configWithSource:(TalentTeacherModel *)sourceModel callback:(FollowTalentAction)callback {
  47. if (callback) {
  48. self.callback = callback;
  49. }
  50. self.sourceModel = sourceModel;
  51. if (sourceModel.living) {
  52. self.liveView.hidden = NO;
  53. self.animationBgView.hidden = NO;
  54. if ([self.animationView isAnimationPlaying] == NO) {
  55. [self.animationView play];
  56. }
  57. }
  58. else {
  59. self.liveView.hidden = YES;
  60. self.animationBgView.hidden = YES;
  61. if ([self.animationView isAnimationPlaying] == YES) {
  62. [self.animationView stop];
  63. }
  64. }
  65. [self.teacherAvatar sd_setImageWithURL:[NSURL URLWithString:[sourceModel.avatar getUrlEndcodeString]] placeholderImage:[UIImage imageNamed:USERDEFAULT_LOGO]];
  66. if ([NSString isEmptyString:sourceModel.username]) {
  67. self.teacherName.text = [NSString stringWithFormat:@"游客%.0f",sourceModel.userId];
  68. }
  69. else {
  70. self.teacherName.text = [NSString stringWithFormat:@"%@",sourceModel.username];
  71. }
  72. if ([NSString isEmptyString:sourceModel.graduateSchool]) {
  73. self.graduateSchool.text = @"认证达人";
  74. }
  75. else {
  76. self.graduateSchool.text = [NSString returnNoNullStringWithString:sourceModel.graduateSchool];
  77. }
  78. }
  79. - (IBAction)followAction:(id)sender {
  80. if (self.callback) {
  81. self.callback([NSString stringWithFormat:@"%.0f",self.sourceModel.userId]);
  82. }
  83. }
  84. - (LOTAnimationView *)animationView {
  85. if (!_animationView) {
  86. _animationView = [LOTAnimationView animationNamed:@"talentAnimation.json"];
  87. _animationView.loopAnimation = YES;
  88. }
  89. return _animationView;
  90. }
  91. @end