Files
yinmeng-ios/xplan-ios/Main/Room/View/AnimationView/XPRoomNobleLevelUpView.m
2022-03-10 18:55:18 +08:00

118 lines
4.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"
@interface XPRoomNobleLevelUpView ()
///动画管理类
@property (strong, nonatomic) SVGAParser *parser;
///糖果树特效
@property (nonatomic,strong) SVGAImageView *nobleView;
@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);
}];
}
- (NSAttributedString *)createAttribute:(NSString * )text color:(UIColor *)color {
NSDictionary * attribute = @{NSFontAttributeName:[UIFont systemFontOfSize:22], NSForegroundColorAttributeName:color};
NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:text attributes:attribute];
return attr;
}
- (NSAttributedString *)createImageAttrribute:(NSString *)imageName {
NSTextAttachment * attachment = [[NSTextAttachment alloc] init];
attachment.bounds = CGRectMake(0, 0, 12, 12);
attachment.image = [UIImage imageNamed:@"mine_normal_my_dressup"];
NSAttributedString * starAttribute = [NSMutableAttributedString attributedStringWithAttachment:(NSTextAttachment *)attachment];
return starAttribute;
}
#pragma mark - Getters And Setters
- (void)setNobleInfo:(NSDictionary *)nobleInfo {
if (nobleInfo) {
NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init];
[attribute appendAttributedString:[self createAttribute:@"引爆全场!恭喜" color:[UIColor whiteColor]]];
[attribute appendAttributedString:[self createImageAttrribute:@""]];
[attribute appendAttributedString:[self createAttribute:nobleInfo[@"nick"] color:[ThemeColor messageNickColor]]];
[attribute appendAttributedString:[self createAttribute:@"贵族身份升级为" color:[UIColor whiteColor]]];
[attribute appendAttributedString:[self createAttribute:nobleInfo[@"vipName"] color:[ThemeColor appMainColor]]];
[attribute appendAttributedString:[self createAttribute:@"!" color:[UIColor whiteColor]]];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.lineSpacing = 3;
paragraphStyle.alignment = NSTextAlignmentCenter;
[attribute addAttributes:@{NSParagraphStyleAttributeName : paragraphStyle} range:NSMakeRange(0, [attribute length])];
@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 setAttributedText:attribute forKey:@"noble_text_tx"];
[self.nobleView startAnimation];
} failureBlock:^(NSError * _Nullable error) {
}];
// [self.parser parseWithNamed:@"noble_levelUp_banner" inBundle:[NSBundle mainBundle] completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
// @kStrongify(self);
// self.nobleView.loops = 1;
// self.nobleView.clearsAfterStop = NO;
// self.nobleView.videoItem = videoItem;
// [self.nobleView setAttributedText:attribute forKey:@"noble_text_tx"];
// [self.nobleView startAnimation];
// } 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;
}
@end