YOUPAILZBarrageGradientOnlineNotifactionCell.m 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. //
  2. // YOUPAILZBarrageGradientOnlineNotifactionCell.m
  3. // VQU
  4. //
  5. // Created by CY on 2021/4/20.
  6. // Copyright © 2021 leo. All rights reserved.
  7. //
  8. #import "YOUPAILZBarrageGradientOnlineNotifactionCell.h"
  9. @implementation YOUPAILZBarrageGradientOnlineNotifactionCell
  10. - (instancetype)init {
  11. self = [super init];
  12. if (self) {
  13. self.userInteractionEnabled = YES;
  14. }
  15. return self;
  16. }
  17. - (void)prepareForReuse {
  18. [super prepareForReuse];
  19. //因为在点击的时候被改为了红色, 所以在重用的时候, 要重置一下颜色
  20. }
  21. - (void)setBarrageDescriptor:(YOUPAIOCBarrageDescriptor *)barrageDescriptor {
  22. [super setBarrageDescriptor:barrageDescriptor];
  23. self.des = (YOUPAIOCBarrageTextDescriptor *)barrageDescriptor;
  24. }
  25. - (void)youpaifupdateSubviewsData {
  26. [super youpaifupdateSubviewsData];
  27. for (UIView *subview in self.subviews) {
  28. [subview removeFromSuperview];
  29. }
  30. self.backgroundColor = [UIColor clearColor];
  31. self.dataModel = self.des.dataModel;
  32. UIImageView *vipImgV = [[UIImageView alloc] init];
  33. vipImgV.contentMode = UIViewContentModeScaleAspectFit;
  34. [vipImgV sd_setImageWithURL:[LCTools getImageUrlWithAddress:self.dataModel.vip_icon]];
  35. [self addSubview:vipImgV];
  36. [vipImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  37. make.centerY.equalTo(self);
  38. make.left.offset(0.0f);
  39. make.size.mas_offset(CGSizeMake(57.0f, 35.0f));
  40. }];
  41. UIView *backView = [[UIView alloc] init];
  42. [self addSubview:backView];
  43. [backView mas_makeConstraints:^(MASConstraintMaker *make) {
  44. if (self.dataModel.vip_icon.length == 0) {
  45. make.left.offset(0.0f);
  46. }else{
  47. make.left.equalTo(vipImgV.mas_centerX);
  48. }
  49. make.centerY.equalTo(vipImgV);
  50. make.height.offset(30.0f);
  51. }];
  52. [self bringSubviewToFront:vipImgV];
  53. if (self.dataModel.vip_icon.length == 0) {
  54. vipImgV.hidden = YES;
  55. }else{
  56. vipImgV.hidden = NO;
  57. }
  58. UILabel *contentL = [[UILabel alloc] init];
  59. [backView addSubview:contentL];
  60. contentL.attributedText = [LCTools setRichTextWithTitle:[NSString stringWithFormat:@" %@ ",self.dataModel.nickname] subTitle:@"上线了!" titleColor:HexColorFromRGB(0xFFDD8D) subTitleColor:[UIColor whiteColor] titleFontSize:13.0f subTitleFontSize:13.0f];
  61. [contentL mas_makeConstraints:^(MASConstraintMaker *make) {
  62. if (self.dataModel.vip_icon.length == 0) {
  63. make.left.offset(5.0f);
  64. }else{
  65. make.left.equalTo(vipImgV.mas_right).offset(3.0f);
  66. }
  67. make.top.bottom.offset(0.0f);
  68. make.right.offset(-30.0f);
  69. }];
  70. [self addGradientLayerWithBackView:backView];
  71. }
  72. - (void)layoutSubviews {
  73. [super layoutSubviews];
  74. }
  75. - (void)youpaiflayoutContentSubviews {
  76. [super youpaiflayoutContentSubviews];
  77. }
  78. - (void)youpaifconvertContentToImage {
  79. /*
  80. UIImage *contentImage = [self.layer youpaifconvertContentToImageWithSize:CGSizeMake(CGRectGetMaxX(self.backView.frame), CGRectGetMaxY(self.backView.frame))];
  81. [self.layer setContents:(__bridge id)contentImage.CGImage];
  82. */
  83. }
  84. - (void)removeSubViewsAndSublayers {
  85. //如果不要删除leftImageView, middleImageView, rightImageView, textLabel, 只需重写这个方法并留空就可以了.
  86. //比如: 你想在这个cell被点击的时候, 修改文本颜色
  87. _gradientLayer = nil;
  88. }
  89. - (void)youpaifaddBarrageAnimationWithDelegate:(id<CAAnimationDelegate>)animationDelegate {
  90. if (!self.superview) {
  91. return;
  92. }
  93. CGPoint startCenter = CGPointMake(CGRectGetMaxX(self.superview.bounds) + CGRectGetWidth(self.bounds)/2, self.center.y);
  94. CGPoint stopCenter = CGPointMake((CGRectGetWidth(self.bounds)/2) + 20, self.center.y);
  95. CGPoint endCenter = CGPointMake(-(CGRectGetWidth(self.bounds)/2), self.center.y);
  96. ///*
  97. CAKeyframeAnimation *walkAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
  98. walkAnimation.values = @[[NSValue valueWithCGPoint:startCenter], [NSValue valueWithCGPoint:stopCenter], [NSValue valueWithCGPoint:stopCenter], [NSValue valueWithCGPoint:endCenter]];
  99. walkAnimation.keyTimes = @[@(0.0), @(0.35), @(0.75), @(1.0)];
  100. walkAnimation.duration = self.barrageDescriptor.animationDuration;
  101. walkAnimation.repeatCount = 1;
  102. walkAnimation.delegate = animationDelegate;
  103. walkAnimation.removedOnCompletion = NO;
  104. walkAnimation.fillMode = kCAFillModeForwards;
  105. [self.layer addAnimation:walkAnimation forKey:kBarrageAnimation];
  106. }
  107. - (void)addGradientLayerWithBackView:(UIView *)backView{
  108. if (!self.des.gradientColor) {
  109. return;
  110. }
  111. [self layoutIfNeeded];
  112. [LCTools clipCorner:UIRectCornerTopLeft|UIRectCornerBottomLeft View:backView size:CGSizeMake(15.0f, 15.0f)];
  113. UIColor *color = HexColorFromRGB(0xC55700);
  114. CAGradientLayer *gradientLayer = [CAGradientLayer layer];
  115. gradientLayer.colors = @[
  116. (__bridge id)(color).CGColor,
  117. (__bridge id)[(color) colorWithAlphaComponent:0.5].CGColor,
  118. (__bridge id)[(color) colorWithAlphaComponent:0.0].CGColor
  119. ];
  120. gradientLayer.locations = @[@0.2,@0.6,@1.0];
  121. gradientLayer.startPoint = CGPointMake(0, 0);
  122. gradientLayer.endPoint = CGPointMake(1.0, 0);
  123. gradientLayer.frame = CGRectMake(0.0, 0.0, backView.frame.size.width, backView.frame.size.height);
  124. UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:gradientLayer.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerTopLeft cornerRadii:CGSizeMake(0, 0)];
  125. CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
  126. maskLayer.frame = gradientLayer.bounds;
  127. maskLayer.path = maskPath.CGPath;
  128. gradientLayer.mask = maskLayer;
  129. _gradientLayer = gradientLayer;
  130. [backView.layer insertSublayer:gradientLayer atIndex:0];
  131. }
  132. @end