162 lines
6.2 KiB
Objective-C
162 lines
6.2 KiB
Objective-C
//
|
||
// 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"
|
||
#import "NetImageView.h"
|
||
#import <YYText/YYText.h>
|
||
|
||
@interface XPRoomNobleLevelUpView ()
|
||
///动画管理类
|
||
@property (strong, nonatomic) SVGAParser *parser;
|
||
|
||
///贵族特效
|
||
@property (nonatomic,strong) SVGAImageView *nobleView;
|
||
|
||
@property (nonatomic, strong) UILabel *firstLabel;
|
||
///用户头像
|
||
@property (nonatomic, strong) NetImageView *imageView;
|
||
///贵族信息
|
||
@property (nonatomic, strong) UILabel *secondLabel;
|
||
|
||
@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 {
|
||
_nobleInfo = nobleInfo;
|
||
self.imageView.imageUrl = nobleInfo[@"avatar"];
|
||
|
||
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) {
|
||
|
||
}];
|
||
///绘制自定义view
|
||
[self.nobleView setDrawingBlock:^(CALayer *contentLayer, NSInteger frameIndex) {
|
||
@kStrongify(self);
|
||
CGFloat height = contentLayer.bounds.size.height;
|
||
CGFloat totalWidth = 0;
|
||
|
||
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;
|
||
|
||
NSMutableAttributedString * attribute1 = [[NSMutableAttributedString alloc] init];
|
||
[attribute1 appendAttributedString:[self createAttribute:@" " color:[ThemeColor giftBroadcastNumberColor]]];
|
||
[attribute1 appendAttributedString:[self createAttribute:nobleInfo[@"nick"] color:[ThemeColor giftBroadcastNumberColor]]];
|
||
[attribute1 appendAttributedString:[self createAttribute:@" " color:[ThemeColor giftBroadcastNumberColor]]];
|
||
[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.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];
|
||
}
|
||
} 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];
|
||
}
|
||
return _secondLabel;
|
||
}
|
||
|
||
- (NetImageView *)imageView {
|
||
if (!_imageView) {
|
||
NetImageConfig *config = [[NetImageConfig alloc]init];
|
||
config.placeHolder = [UIImageConstant defaultAvatarPlaceholder];
|
||
config.autoLoad = YES;
|
||
_imageView = [[NetImageView alloc] initWithConfig:config];
|
||
}
|
||
return _imageView;
|
||
}
|
||
|
||
@end
|