YOUPAIOCBarrageCoustmerCell.m 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. //
  2. // YOUPAIOCBarrageCoustmerCell.m
  3. // livePro
  4. //
  5. // Created by leo on 2019/11/25.
  6. // Copyright © 2019 caiPro. All rights reserved.
  7. //
  8. #import "YOUPAIOCBarrageCoustmerCell.h"
  9. #import "UIImageView+WebCache.h"
  10. @implementation YOUPAIOCBarrageCoustmerCell
  11. - (instancetype)init {
  12. self = [super init];
  13. if (self) {
  14. self.userInteractionEnabled = YES;
  15. }
  16. return self;
  17. }
  18. - (void)prepareForReuse {
  19. [super prepareForReuse];
  20. //因为在点击的时候被改为了红色, 所以在重用的时候, 要重置一下颜色
  21. }
  22. - (void)setBarrageDescriptor:(YOUPAIOCBarrageDescriptor *)barrageDescriptor {
  23. [super setBarrageDescriptor:barrageDescriptor];
  24. self.des = (YOUPAIOCBarrageTextDescriptor *)barrageDescriptor;
  25. }
  26. - (void)youpaifupdateSubviewsData {
  27. [super youpaifupdateSubviewsData];
  28. for (UIView *subview in self.subviews) {
  29. [subview removeFromSuperview];
  30. }
  31. self.backgroundColor = [UIColor clearColor];
  32. self.dataModel = self.des.dataModel;
  33. UIImageView *vipImgV = [[UIImageView alloc] init];
  34. vipImgV.contentMode = UIViewContentModeScaleAspectFit;
  35. [vipImgV sd_setImageWithURL:[LCTools getImageUrlWithAddress:self.dataModel.vip_icon]];
  36. [self addSubview:vipImgV];
  37. [vipImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  38. make.centerY.equalTo(self);
  39. make.left.offset(0.0f);
  40. make.size.mas_offset(CGSizeMake(57.0f, 35.0f));
  41. }];
  42. UIView *backView = [[UIView alloc] init];
  43. [self addSubview:backView];
  44. [backView mas_makeConstraints:^(MASConstraintMaker *make) {
  45. if (self.dataModel.vip_icon.length == 0) {
  46. make.left.offset(0.0f);
  47. }else{
  48. make.left.equalTo(vipImgV.mas_centerX);
  49. }
  50. make.centerY.equalTo(vipImgV);
  51. make.height.offset(30.0f);
  52. }];
  53. [self bringSubviewToFront:vipImgV];
  54. if (self.dataModel.vip_icon.length == 0) {
  55. vipImgV.hidden = YES;
  56. }else{
  57. vipImgV.hidden = NO;
  58. }
  59. UILabel *contentL = [[UILabel alloc] init];
  60. contentL.textColor = [UIColor whiteColor];
  61. contentL.numberOfLines = 0;
  62. contentL.font = LCFont(13.0f);
  63. contentL.textAlignment = NSTextAlignmentCenter;
  64. [backView addSubview:contentL];
  65. NSString *textStr = [NSString stringWithFormat:@"%@ 送给 %@ %@x%@",self.dataModel.nickname,self.dataModel.tonickname,self.dataModel.giftname,@(self.dataModel.gifttotal)];
  66. NSMutableAttributedString *attributer = [[NSMutableAttributedString alloc]initWithString:textStr];
  67. ;
  68. [attributer addAttribute:NSForegroundColorAttributeName
  69. value:HexColorFromRGB(0xFFDC80)
  70. range:[textStr rangeOfString:self.dataModel.nickname]];
  71. [attributer addAttribute:NSForegroundColorAttributeName
  72. value:HexColorFromRGB(0xFFDC80)
  73. range:[textStr rangeOfString:self.dataModel.tonickname]];
  74. contentL.attributedText = attributer;
  75. [contentL mas_makeConstraints:^(MASConstraintMaker *make) {
  76. if (self.dataModel.vip_icon.length == 0) {
  77. make.left.offset(5.0f);
  78. }else{
  79. make.left.equalTo(vipImgV.mas_right).offset(3.0f);
  80. }
  81. make.centerY.equalTo(backView);
  82. }];
  83. UIImageView *giftImgV = [[UIImageView alloc] init];
  84. giftImgV.contentMode = UIViewContentModeScaleAspectFit;
  85. [giftImgV setImage:[LCTools giftImgWithGiftUrlStr:self.dataModel.giftimg]];
  86. [backView addSubview:giftImgV];
  87. [giftImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  88. make.left.equalTo(contentL.mas_right).offset(3.0f);
  89. make.centerY.equalTo(backView);
  90. make.size.mas_offset(CGSizeMake(30.0f, 30.0f));
  91. make.right.offset(-10.0f);
  92. }];
  93. [self addGradientLayerWithBackView:backView];
  94. }
  95. - (void)layoutSubviews {
  96. [super layoutSubviews];
  97. }
  98. - (void)youpaiflayoutContentSubviews {
  99. [super youpaiflayoutContentSubviews];
  100. }
  101. - (void)addGradientLayerWithBackView:(UIView *)backView{
  102. if (!self.des.gradientColor) {
  103. return;
  104. }
  105. [self layoutIfNeeded];
  106. [LCTools clipCorner:UIRectCornerTopLeft|UIRectCornerBottomLeft View:backView size:CGSizeMake(15.0f, 15.0f)];
  107. UIColor *color = HexColorFromRGB(0xC55700);
  108. CAGradientLayer *gradientLayer = [CAGradientLayer layer];
  109. gradientLayer.colors = @[
  110. (__bridge id)(color).CGColor,
  111. (__bridge id)[(color) colorWithAlphaComponent:0.5].CGColor,
  112. (__bridge id)[(color) colorWithAlphaComponent:0.0].CGColor
  113. ];
  114. gradientLayer.locations = @[@0.2,@0.6,@1.0];
  115. gradientLayer.startPoint = CGPointMake(0, 0);
  116. gradientLayer.endPoint = CGPointMake(1.0, 0);
  117. gradientLayer.frame = CGRectMake(0.0, 0.0, backView.frame.size.width, backView.frame.size.height);
  118. UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:gradientLayer.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerTopLeft cornerRadii:CGSizeMake(0, 0)];
  119. CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
  120. maskLayer.frame = gradientLayer.bounds;
  121. maskLayer.path = maskPath.CGPath;
  122. gradientLayer.mask = maskLayer;
  123. _gradientLayer = gradientLayer;
  124. [backView.layer insertSublayer:gradientLayer atIndex:0];
  125. }
  126. - (void)youpaifconvertContentToImage {
  127. /*
  128. UIImage *contentImage = [self.layer youpaifconvertContentToImageWithSize:CGSizeMake(CGRectGetMaxX(self.backView.frame), CGRectGetMaxY(self.backView.frame))];
  129. [self.layer setContents:(__bridge id)contentImage.CGImage];
  130. */
  131. }
  132. - (void)removeSubViewsAndSublayers {
  133. //如果不要删除leftImageView, middleImageView, rightImageView, textLabel, 只需重写这个方法并留空就可以了.
  134. //比如: 你想在这个cell被点击的时候, 修改文本颜色
  135. }
  136. - (void)youpaifaddBarrageAnimationWithDelegate:(id<CAAnimationDelegate>)animationDelegate {
  137. if (!self.superview) {
  138. return;
  139. }
  140. CGPoint startCenter = CGPointMake(CGRectGetMaxX(self.superview.bounds) + CGRectGetWidth(self.bounds)/2, self.center.y);
  141. CGPoint stopCenter = CGPointMake((CGRectGetWidth(self.bounds)/2) + 20, self.center.y);
  142. CGPoint endCenter = CGPointMake(-(CGRectGetWidth(self.bounds)/2), self.center.y);
  143. ///*
  144. CAKeyframeAnimation *walkAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
  145. walkAnimation.values = @[[NSValue valueWithCGPoint:startCenter], [NSValue valueWithCGPoint:stopCenter], [NSValue valueWithCGPoint:stopCenter], [NSValue valueWithCGPoint:endCenter]];
  146. walkAnimation.keyTimes = @[@(0.0), @(0.35), @(0.75), @(1.0)];
  147. walkAnimation.duration = self.barrageDescriptor.animationDuration;
  148. walkAnimation.repeatCount = 1;
  149. walkAnimation.delegate = animationDelegate;
  150. walkAnimation.removedOnCompletion = NO;
  151. walkAnimation.fillMode = kCAFillModeForwards;
  152. [self.layer addAnimation:walkAnimation forKey:kBarrageAnimation];
  153. }
  154. /*
  155. // Only override drawRect: if you perform custom drawing.
  156. // An empty implementation adversely affects performance during animation.
  157. - (void)drawRect:(CGRect)rect {
  158. // Drawing code
  159. }
  160. */
  161. @end