Files
yinmeng-ios/xplan-ios/Main/Room/View/AnimationView/XPRoomNobleLevelUpView.m

162 lines
6.2 KiB
Mathematica
Raw Normal View History

//
// XPRoomNobleLevelUpView.m
// xplan-ios
//
// Created by GreenLand on 2022/1/10.
//
#import "XPRoomNobleLevelUpView.h"
///Third
#import <Masonry/Masonry.h>
#import <SVGA.h>
#import "XPMacro.h"
#import "ThemeColor+Room.h"
2022-01-12 16:33:57 +08:00
#import "NetImageView.h"
#import <YYText/YYText.h>
@interface XPRoomNobleLevelUpView ()
///
@property (strong, nonatomic) SVGAParser *parser;
2022-01-12 16:33:57 +08:00
///
@property (nonatomic,strong) SVGAImageView *nobleView;
2022-01-12 16:33:57 +08:00
@property (nonatomic, strong) UILabel *firstLabel;
2022-01-12 16:33:57 +08:00
///
@property (nonatomic, strong) NetImageView *imageView;
///
@property (nonatomic, strong) UILabel *secondLabel;
2022-01-12 16:33:57 +08:00
@end
@implementation XPRoomNobleLevelUpView
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self initSubViews];
[self initSubViewConstraints];
}
return self;
}
#pragma mark - Private Method
- (void)initSubViews {
[self addSubview:self.nobleView];
}
- (void)initSubViewConstraints {
[self.nobleView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.top.mas_equalTo(self);
make.height.mas_equalTo(90);
}];
}
- (NSMutableAttributedString *)createAttribute:(NSString * )text color:(UIColor *)color {
NSDictionary * attribute = @{NSFontAttributeName:[UIFont systemFontOfSize:22], NSForegroundColorAttributeName:color};
NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:text attributes:attribute];
return attr;
}
#pragma mark - Getters And Setters
- (void)setNobleInfo:(NSDictionary *)nobleInfo {
2022-01-12 16:33:57 +08:00
_nobleInfo = nobleInfo;
self.imageView.imageUrl = nobleInfo[@"avatar"];
2022-01-12 16:33:57 +08:00
if (nobleInfo) {
@kWeakify(self);
[self.parser parseWithURL:[NSURL URLWithString:nobleInfo[@"floatPic"]] completionBlock:^(SVGAVideoEntity * _Nullable videoItem) {
@kStrongify(self);
self.nobleView.loops = 1;
self.nobleView.clearsAfterStop = NO;
self.nobleView.videoItem = videoItem;
[self.nobleView startAnimation];
} failureBlock:^(NSError * _Nullable error) {
}];
2022-01-12 16:33:57 +08:00
///view
[self.nobleView setDrawingBlock:^(CALayer *contentLayer, NSInteger frameIndex) {
@kStrongify(self);
CGFloat height = contentLayer.bounds.size.height;
CGFloat totalWidth = 0;
2022-01-12 16:33:57 +08:00
NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init];
[attribute appendAttributedString:[self createAttribute:@"引爆全场!恭喜 " color:[UIColor whiteColor]]];
CGFloat width1 = [attribute.string boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, height) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:22]} context:nil].size.width;
self.firstLabel.attributedText = attribute;
2022-01-12 16:33:57 +08:00
NSMutableAttributedString * attribute1 = [[NSMutableAttributedString alloc] init];
[attribute1 appendAttributedString:[self createAttribute:@" " color:[ThemeColor giftBroadcastNumberColor]]];
2022-01-12 16:33:57 +08:00
[attribute1 appendAttributedString:[self createAttribute:nobleInfo[@"nick"] color:[ThemeColor giftBroadcastNumberColor]]];
[attribute1 appendAttributedString:[self createAttribute:@" " color:[ThemeColor giftBroadcastNumberColor]]];
2022-01-12 16:33:57 +08:00
[attribute1 appendAttributedString:[self createAttribute:[NSString stringWithFormat:@"贵族身份升级为%@!", nobleInfo[@"currVipName"]] color:[UIColor whiteColor]]];
CGFloat width2 = [attribute1.string boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, height) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:22]} context:nil].size.width;
self.secondLabel.attributedText = attribute1;
totalWidth += ((width1 + width2) * 12/22 + 50);
CGFloat originL = (KScreenWidth - (totalWidth > KScreenWidth ? KScreenWidth : totalWidth)) * 0.5;
if (KScreenHeight != 667) {///iOS14.0iPhone8
self.firstLabel.layer.frame = CGRectMake(originL, 0, width1, height);
[contentLayer addSublayer:self.firstLabel.layer];
UIImageView *imageView = [[UIImageView alloc] initWithImage:self.imageView.image];
imageView.layer.frame = CGRectMake(originL + width1, (height - 50) * 0.5, 50, 50);
imageView.layer.cornerRadius = 25.0f;
imageView.layer.masksToBounds = YES;
[contentLayer addSublayer:imageView.layer];
self.secondLabel.layer.frame = CGRectMake(originL + width1 + 50, 0, width2, height);
[contentLayer addSublayer:self.secondLabel.layer];
} else {
totalWidth -= 50;
CGFloat originL = (KScreenWidth - (totalWidth > KScreenWidth ? KScreenWidth : totalWidth)) * 0.5;
self.firstLabel.layer.frame = CGRectMake(originL, 0, width1, height);
[contentLayer addSublayer:self.firstLabel.layer];
self.secondLabel.layer.frame = CGRectMake(originL + width1, 0, width2, height);
[contentLayer addSublayer:self.secondLabel.layer];
}
2022-01-12 16:33:57 +08:00
} forKey:@"noble_text_tx"];
}
}
- (SVGAImageView *)nobleView {
if (!_nobleView) {
_nobleView = [[SVGAImageView alloc]init];
_nobleView.backgroundColor = [UIColor clearColor];
_nobleView.userInteractionEnabled = NO;
}
return _nobleView;
}
- (SVGAParser *)parser {
if (!_parser) {
_parser = [[SVGAParser alloc]init];
}
return _parser;
}
- (UILabel *)firstLabel {
if (!_firstLabel) {
_firstLabel = [[UILabel alloc] init];
}
return _firstLabel;
}
- (UILabel *)secondLabel{
if (!_secondLabel) {
_secondLabel = [[UILabel alloc] init];
2022-01-12 16:33:57 +08:00
}
return _secondLabel;
2022-01-12 16:33:57 +08:00
}
- (NetImageView *)imageView {
if (!_imageView) {
NetImageConfig *config = [[NetImageConfig alloc]init];
config.placeHolder = [UIImageConstant defaultAvatarPlaceholder];
config.autoLoad = YES;
_imageView = [[NetImageView alloc] initWithConfig:config];
2022-01-12 16:33:57 +08:00
}
return _imageView;
2022-01-12 16:33:57 +08:00
}
@end