YOUPAILZBarrageGradientVipNotifactionCell.m 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. //
  2. // YOUPAILZBarrageGradientVipNotifactionCell.m
  3. // VQU
  4. //
  5. // Created by CY on 2021/10/21.
  6. // Copyright © 2021 MS. All rights reserved.
  7. //
  8. #import "YOUPAILZBarrageGradientVipNotifactionCell.h"
  9. @implementation YOUPAILZBarrageGradientVipNotifactionCell
  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. UIView *bgV = [[UIView alloc] init];
  33. bgV.layer.cornerRadius = 15.0f;
  34. bgV.clipsToBounds = YES;
  35. bgV.backgroundColor = [HexColorFromRGB(0xC440E3) colorWithAlphaComponent:0.3f];
  36. [self addSubview:bgV];
  37. [bgV mas_makeConstraints:^(MASConstraintMaker *make) {
  38. make.height.offset(30.0f);
  39. // make.centerY.equalTo(self);
  40. make.left.offset(0.0f);
  41. }];
  42. UIImageView *vipImgV = [[UIImageView alloc] init];
  43. vipImgV.contentMode = UIViewContentModeScaleAspectFit;
  44. [vipImgV sd_setImageWithURL:[LCTools getImageUrlWithAddress:self.dataModel.vip_icon]];
  45. [bgV addSubview:vipImgV];
  46. [vipImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  47. make.centerY.equalTo(bgV);
  48. make.right.offset(-7.0f);
  49. make.size.mas_offset(CGSizeMake(30.0f, 19.0f));
  50. }];
  51. UILabel *contentL = [[UILabel alloc] init];
  52. contentL.font = LCBoldFont(13.0f);
  53. contentL.textColor = [UIColor whiteColor];
  54. contentL.text = [NSString stringWithFormat:@"恭喜 %@ 成为贵族",self.dataModel.nickname];
  55. NSMutableAttributedString *attributedText=[[NSMutableAttributedString alloc]initWithString:contentL.text];
  56. NSRange range = [contentL.text rangeOfString:self.dataModel.nickname];
  57. [attributedText addAttribute:NSForegroundColorAttributeName value:HexColorFromRGB(0xFFDD8D) range:range];
  58. contentL.attributedText = attributedText.copy;
  59. [bgV addSubview:contentL];
  60. [contentL mas_makeConstraints:^(MASConstraintMaker *make) {
  61. make.left.offset(7.0f);
  62. make.centerY.equalTo(bgV);
  63. make.right.equalTo(vipImgV.mas_left).offset(-5.0f);
  64. }];
  65. [self layoutIfNeeded];
  66. }
  67. - (void)layoutSubviews {
  68. [super layoutSubviews];
  69. }
  70. - (void)youpaiflayoutContentSubviews {
  71. [super youpaiflayoutContentSubviews];
  72. }
  73. - (void)youpaifconvertContentToImage {
  74. /*
  75. UIImage *contentImage = [self.layer youpaifconvertContentToImageWithSize:CGSizeMake(CGRectGetMaxX(self.backView.frame), CGRectGetMaxY(self.backView.frame))];
  76. [self.layer setContents:(__bridge id)contentImage.CGImage];
  77. */
  78. }
  79. - (void)removeSubViewsAndSublayers {
  80. //如果不要删除leftImageView, middleImageView, rightImageView, textLabel, 只需重写这个方法并留空就可以了.
  81. //比如: 你想在这个cell被点击的时候, 修改文本颜色
  82. // _gradientLayer = nil;
  83. }
  84. - (void)youpaifaddBarrageAnimationWithDelegate:(id<CAAnimationDelegate>)animationDelegate {
  85. if (!self.superview) {
  86. return;
  87. }
  88. CGPoint startCenter = CGPointMake(CGRectGetMaxX(self.superview.bounds) + CGRectGetWidth(self.bounds)/2, self.center.y);
  89. CGPoint stopCenter = CGPointMake((CGRectGetWidth(self.bounds)/2) + 20, self.center.y);
  90. CGPoint endCenter = CGPointMake(-(CGRectGetWidth(self.bounds)/2), self.center.y);
  91. ///*
  92. CAKeyframeAnimation *walkAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
  93. walkAnimation.values = @[[NSValue valueWithCGPoint:startCenter], [NSValue valueWithCGPoint:stopCenter], [NSValue valueWithCGPoint:stopCenter], [NSValue valueWithCGPoint:endCenter]];
  94. walkAnimation.keyTimes = @[@(0.0), @(0.35), @(0.75), @(1.0)];
  95. walkAnimation.duration = self.barrageDescriptor.animationDuration;
  96. walkAnimation.repeatCount = 1;
  97. walkAnimation.delegate = animationDelegate;
  98. walkAnimation.removedOnCompletion = NO;
  99. walkAnimation.fillMode = kCAFillModeForwards;
  100. [self.layer addAnimation:walkAnimation forKey:kBarrageAnimation];
  101. }
  102. //- (void)addGradientLayerWithBackView:(UIView *)backView{
  103. // if (!self.des.gradientColor) {
  104. // return;
  105. // }
  106. // [self layoutIfNeeded];
  107. //
  108. // CAGradientLayer *gradientLayer = [CAGradientLayer layer];
  109. // gradientLayer.colors = @[
  110. // (__bridge id)[HexColorFromRGB(0xC440E3) colorWithAlphaComponent:0.3f].CGColor,
  111. // (__bridge id)[HexColorFromRGB(0xC440E3) colorWithAlphaComponent:0.3f].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. //
  119. // UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:gradientLayer.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerTopLeft cornerRadii:CGSizeMake(0, 0)];
  120. // CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
  121. // maskLayer.frame = gradientLayer.bounds;
  122. // maskLayer.path = maskPath.CGPath;
  123. // gradientLayer.mask = maskLayer;
  124. // _gradientLayer = gradientLayer;
  125. // [backView.layer insertSublayer:gradientLayer atIndex:0];
  126. //}
  127. @end