123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- //
- // YOUPAILZBarrageGradientOnlineNotifactionCell.m
- // VQU
- //
- // Created by CY on 2021/4/20.
- // Copyright © 2021 leo. All rights reserved.
- //
- #import "YOUPAILZBarrageGradientOnlineNotifactionCell.h"
- @implementation YOUPAILZBarrageGradientOnlineNotifactionCell
- - (instancetype)init {
- self = [super init];
- if (self) {
- self.userInteractionEnabled = YES;
- }
-
- return self;
- }
- - (void)prepareForReuse {
- [super prepareForReuse];
-
- //因为在点击的时候被改为了红色, 所以在重用的时候, 要重置一下颜色
- }
- - (void)setBarrageDescriptor:(YOUPAIOCBarrageDescriptor *)barrageDescriptor {
- [super setBarrageDescriptor:barrageDescriptor];
- self.des = (YOUPAIOCBarrageTextDescriptor *)barrageDescriptor;
- }
- - (void)youpaifupdateSubviewsData {
- [super youpaifupdateSubviewsData];
- for (UIView *subview in self.subviews) {
- [subview removeFromSuperview];
- }
- self.backgroundColor = [UIColor clearColor];
- self.dataModel = self.des.dataModel;
-
- UIImageView *vipImgV = [[UIImageView alloc] init];
- vipImgV.contentMode = UIViewContentModeScaleAspectFit;
- [vipImgV sd_setImageWithURL:[LCTools getImageUrlWithAddress:self.dataModel.vip_icon]];
- [self addSubview:vipImgV];
- [vipImgV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(self);
- make.left.offset(0.0f);
- make.size.mas_offset(CGSizeMake(57.0f, 35.0f));
- }];
-
-
- UIView *backView = [[UIView alloc] init];
- [self addSubview:backView];
- [backView mas_makeConstraints:^(MASConstraintMaker *make) {
- if (self.dataModel.vip_icon.length == 0) {
- make.left.offset(0.0f);
- }else{
- make.left.equalTo(vipImgV.mas_centerX);
- }
- make.centerY.equalTo(vipImgV);
- make.height.offset(30.0f);
- }];
- [self bringSubviewToFront:vipImgV];
- if (self.dataModel.vip_icon.length == 0) {
- vipImgV.hidden = YES;
- }else{
- vipImgV.hidden = NO;
- }
-
- UILabel *contentL = [[UILabel alloc] init];
- [backView addSubview:contentL];
- contentL.attributedText = [LCTools setRichTextWithTitle:[NSString stringWithFormat:@" %@ ",self.dataModel.nickname] subTitle:@"上线了!" titleColor:HexColorFromRGB(0xFFDD8D) subTitleColor:[UIColor whiteColor] titleFontSize:13.0f subTitleFontSize:13.0f];
- [contentL mas_makeConstraints:^(MASConstraintMaker *make) {
- if (self.dataModel.vip_icon.length == 0) {
- make.left.offset(5.0f);
- }else{
- make.left.equalTo(vipImgV.mas_right).offset(3.0f);
- }
- make.top.bottom.offset(0.0f);
- make.right.offset(-30.0f);
- }];
-
- [self addGradientLayerWithBackView:backView];
- }
- - (void)layoutSubviews {
- [super layoutSubviews];
-
- }
- - (void)youpaiflayoutContentSubviews {
- [super youpaiflayoutContentSubviews];
- }
- - (void)youpaifconvertContentToImage {
- /*
- UIImage *contentImage = [self.layer youpaifconvertContentToImageWithSize:CGSizeMake(CGRectGetMaxX(self.backView.frame), CGRectGetMaxY(self.backView.frame))];
- [self.layer setContents:(__bridge id)contentImage.CGImage];
- */
- }
- - (void)removeSubViewsAndSublayers {
- //如果不要删除leftImageView, middleImageView, rightImageView, textLabel, 只需重写这个方法并留空就可以了.
- //比如: 你想在这个cell被点击的时候, 修改文本颜色
- _gradientLayer = nil;
- }
- - (void)youpaifaddBarrageAnimationWithDelegate:(id<CAAnimationDelegate>)animationDelegate {
- if (!self.superview) {
- return;
- }
-
- CGPoint startCenter = CGPointMake(CGRectGetMaxX(self.superview.bounds) + CGRectGetWidth(self.bounds)/2, self.center.y);
- CGPoint stopCenter = CGPointMake((CGRectGetWidth(self.bounds)/2) + 20, self.center.y);
- CGPoint endCenter = CGPointMake(-(CGRectGetWidth(self.bounds)/2), self.center.y);
- ///*
- CAKeyframeAnimation *walkAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
- walkAnimation.values = @[[NSValue valueWithCGPoint:startCenter], [NSValue valueWithCGPoint:stopCenter], [NSValue valueWithCGPoint:stopCenter], [NSValue valueWithCGPoint:endCenter]];
- walkAnimation.keyTimes = @[@(0.0), @(0.35), @(0.75), @(1.0)];
- walkAnimation.duration = self.barrageDescriptor.animationDuration;
- walkAnimation.repeatCount = 1;
- walkAnimation.delegate = animationDelegate;
- walkAnimation.removedOnCompletion = NO;
- walkAnimation.fillMode = kCAFillModeForwards;
-
- [self.layer addAnimation:walkAnimation forKey:kBarrageAnimation];
- }
- - (void)addGradientLayerWithBackView:(UIView *)backView{
- if (!self.des.gradientColor) {
- return;
- }
- [self layoutIfNeeded];
- [LCTools clipCorner:UIRectCornerTopLeft|UIRectCornerBottomLeft View:backView size:CGSizeMake(15.0f, 15.0f)];
- UIColor *color = HexColorFromRGB(0xC55700);
-
- CAGradientLayer *gradientLayer = [CAGradientLayer layer];
- gradientLayer.colors = @[
- (__bridge id)(color).CGColor,
- (__bridge id)[(color) colorWithAlphaComponent:0.5].CGColor,
- (__bridge id)[(color) colorWithAlphaComponent:0.0].CGColor
- ];
- gradientLayer.locations = @[@0.2,@0.6,@1.0];
- gradientLayer.startPoint = CGPointMake(0, 0);
- gradientLayer.endPoint = CGPointMake(1.0, 0);
- gradientLayer.frame = CGRectMake(0.0, 0.0, backView.frame.size.width, backView.frame.size.height);
-
- UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:gradientLayer.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerTopLeft cornerRadii:CGSizeMake(0, 0)];
- CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
- maskLayer.frame = gradientLayer.bounds;
- maskLayer.path = maskPath.CGPath;
- gradientLayer.mask = maskLayer;
- _gradientLayer = gradientLayer;
- [backView.layer insertSublayer:gradientLayer atIndex:0];
- }
- @end
|