2022-01-10 19:59:58 +08:00
|
|
|
|
//
|
|
|
|
|
// 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>
|
2022-01-10 19:59:58 +08:00
|
|
|
|
|
|
|
|
|
@interface XPRoomNobleLevelUpView ()
|
|
|
|
|
///动画管理类
|
|
|
|
|
@property (strong, nonatomic) SVGAParser *parser;
|
2022-01-12 16:33:57 +08:00
|
|
|
|
|
|
|
|
|
///贵族特效
|
2022-01-10 19:59:58 +08:00
|
|
|
|
@property (nonatomic,strong) SVGAImageView *nobleView;
|
2022-01-12 16:33:57 +08:00
|
|
|
|
|
2022-01-17 20:37:07 +08:00
|
|
|
|
@property (nonatomic, strong) UILabel *firstLabel;
|
2022-01-12 16:33:57 +08:00
|
|
|
|
///用户头像
|
|
|
|
|
@property (nonatomic, strong) NetImageView *imageView;
|
|
|
|
|
///贵族信息
|
2022-01-17 20:37:07 +08:00
|
|
|
|
@property (nonatomic, strong) UILabel *secondLabel;
|
2022-01-12 16:33:57 +08:00
|
|
|
|
|
2022-01-10 19:59:58 +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);
|
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-17 20:37:07 +08:00
|
|
|
|
- (NSMutableAttributedString *)createAttribute:(NSString * )text color:(UIColor *)color {
|
2022-01-10 19:59:58 +08:00
|
|
|
|
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;
|
2022-01-17 20:37:07 +08:00
|
|
|
|
self.imageView.imageUrl = nobleInfo[@"avatar"];
|
2022-01-12 16:33:57 +08:00
|
|
|
|
|
2022-01-10 19:59:58 +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;
|
2022-01-17 20:37:07 +08:00
|
|
|
|
CGFloat totalWidth = 0;
|
2022-01-12 16:33:57 +08:00
|
|
|
|
|
|
|
|
|
NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init];
|
2022-05-13 21:19:56 +08:00
|
|
|
|
[attribute appendAttributedString:[self createAttribute:@"引爆全场!恭喜 " color:[UIColor whiteColor]]];
|
2022-01-17 20:37:07 +08:00
|
|
|
|
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];
|
2022-05-13 21:19:56 +08:00
|
|
|
|
[attribute1 appendAttributedString:[self createAttribute:@" " color:[ThemeColor giftBroadcastNumberColor]]];
|
2022-01-12 16:33:57 +08:00
|
|
|
|
[attribute1 appendAttributedString:[self createAttribute:nobleInfo[@"nick"] color:[ThemeColor giftBroadcastNumberColor]]];
|
2022-05-13 22:17:25 +08:00
|
|
|
|
[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;
|
2022-01-17 20:37:07 +08:00
|
|
|
|
self.secondLabel.attributedText = attribute1;
|
|
|
|
|
|
2022-05-13 21:19:56 +08:00
|
|
|
|
totalWidth += ((width1 + width2) * 12/22 + 50);
|
2022-01-17 20:37:07 +08:00
|
|
|
|
CGFloat originL = (KScreenWidth - (totalWidth > KScreenWidth ? KScreenWidth : totalWidth)) * 0.5;
|
2022-05-13 22:17:25 +08:00
|
|
|
|
if (KScreenHeight != 667) {///在iOS14.0上的iPhone8上,无法显示头像,暂时隐藏头像
|
|
|
|
|
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"];
|
2022-01-10 19:59:58 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (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;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-17 20:37:07 +08:00
|
|
|
|
- (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
|
|
|
|
}
|
2022-01-17 20:37:07 +08:00
|
|
|
|
return _secondLabel;
|
2022-01-12 16:33:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-17 20:37:07 +08:00
|
|
|
|
- (NetImageView *)imageView {
|
|
|
|
|
if (!_imageView) {
|
|
|
|
|
NetImageConfig *config = [[NetImageConfig alloc]init];
|
2022-05-13 18:41:52 +08:00
|
|
|
|
config.placeHolder = [UIImageConstant defaultAvatarPlaceholder];
|
2022-01-17 20:37:07 +08:00
|
|
|
|
config.autoLoad = YES;
|
|
|
|
|
_imageView = [[NetImageView alloc] initWithConfig:config];
|
2022-01-12 16:33:57 +08:00
|
|
|
|
}
|
2022-01-17 20:37:07 +08:00
|
|
|
|
return _imageView;
|
2022-01-12 16:33:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-10 19:59:58 +08:00
|
|
|
|
@end
|