Files
peko-ios/YuMi/Modules/YMRoom/View/AnimationView/XPRoomNobleLevelUpView.m
2024-04-11 17:05:27 +08:00

160 lines
5.4 KiB
Objective-C

//
// YMRoomNobleLevelUpView.m
// YUMI
//
// Created by YUMI on 2022/1/10.
//
#import "XPRoomNobleLevelUpView.h"
///Third
#import <Masonry/Masonry.h>
#import <SVGA.h>
#import "YUMIMacroUitls.h"
#import "ThemeColor+Room.h"
#import "NetImageView.h"
#import <pop/POP.h>
@interface XPRoomNobleLevelUpView ()
///动画管理类
@property (strong, nonatomic) SVGAParser *parser;
///VIP特效
@property (nonatomic,strong) SVGAImageView *nobleView;
///用户头像
@property (nonatomic, strong) NetImageView *imageView;
///赠送内容
@property(nonatomic,strong) MarqueeLabel *pi_contentView;
@end
@implementation XPRoomNobleLevelUpView
- (void)dealloc
{
}
- (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];
[self addSubview:self.pi_contentView];
}
- (void)initSubViewConstraints {
[self.nobleView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.trailing.top.mas_equalTo(self);
make.height.mas_equalTo(90);
}];
[self.pi_contentView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(kGetScaleWidth(33));
make.leading.mas_equalTo(kGetScaleWidth(40));
make.trailing.mas_equalTo(-kGetScaleWidth(40));
}];
}
- (NSMutableAttributedString *)createAttribute:(NSString * )text color:(UIColor *)color {
NSDictionary * attribute = @{NSFontAttributeName:[UIFont systemFontOfSize:11], NSForegroundColorAttributeName:color};
NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:text attributes:attribute];
return attr;
}
#pragma mark - Getters And Setters
- (void)setNobleInfo:(NSDictionary *)nobleInfo {
_nobleInfo = nobleInfo;
if (nobleInfo) {
@kWeakify(self);
self.imageView.imageUrl = nobleInfo[@"avatar"];
NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init];
[attribute appendAttributedString:[self createAttribute:YMLocalizedString(@"XPRoomNobleLevelUpView0") color:[UIColor whiteColor]]];
NSTextAttachment * attachment = [[NSTextAttachment alloc] init];
UIImage *iconImage = [self.imageView.image roundedImageWithCornerRadius:self.imageView.image.size.height/2 size:self.imageView.image.size];
attachment.bounds = CGRectMake(0, roundf([UIFont systemFontOfSize:11].capHeight - 25)/2.f, 25, 25);
attachment.image =iconImage;
NSAttributedString * starAttribute = [NSMutableAttributedString attributedStringWithAttachment:(NSTextAttachment *)attachment];
[attribute appendAttributedString:starAttribute];
NSMutableAttributedString * attribute1 = [[NSMutableAttributedString alloc] init];
[attribute1 appendAttributedString:[self createAttribute:@" " color:[DJDKMIMOMColor giftBroadcastNumberColor]]];
[attribute1 appendAttributedString:[self createAttribute:nobleInfo[@"nick"] color:[DJDKMIMOMColor giftBroadcastNumberColor]]];
[attribute1 appendAttributedString:[self createAttribute:@" " color:[DJDKMIMOMColor giftBroadcastNumberColor]]];
[attribute1 appendAttributedString:[self createAttribute:[NSString stringWithFormat:YMLocalizedString(@"XPRoomNobleLevelUpView1"), nobleInfo[@"currVipName"]] color:[UIColor whiteColor]]];
[attribute appendAttributedString:attribute1];
[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];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
self.pi_contentView.attributedText = attribute;
});
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.nobleView pauseAnimation];
});
if(self.completionBlock){
self.completionBlock();
}
} failureBlock:^(NSError * _Nonnull error) {
}];
}
}
- (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;
}
- (NetImageView *)imageView {
if (!_imageView) {
NetImageConfig *config = [[NetImageConfig alloc]init];
config.placeHolder = [UIImageConstant defaultAvatarPlaceholder];
config.autoLoad = YES;
_imageView = [[NetImageView alloc] initWithConfig:config];
}
return _imageView;
}
- (MarqueeLabel *)pi_contentView{
if(!_pi_contentView){
_pi_contentView = [[MarqueeLabel alloc] init];
_pi_contentView.scrollDuration = 6.0;
_pi_contentView.fadeLength = 8.0f;
_pi_contentView.textAlignment = NSTextAlignmentCenter;
}
return _pi_contentView;
}
@end