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

91 lines
2.7 KiB
Mathematica
Raw Normal View History

//
// XPRoomCandyGiftView.m
// xplan-ios
//
// Created by on 2021/12/10.
//
#import "XPRoomCandyGiftView.h"
///Third
#import <Masonry/Masonry.h>
#import <SVGA.h>
#import "XPMacro.h"
#import "ThemeColor+Room.h"
@interface XPRoomCandyGiftView ()
///
@property (strong, nonatomic) SVGAParser *parser;
///
@property (nonatomic,strong) SVGAImageView *candyTreeView;
@end
@implementation XPRoomCandyGiftView
- (void)dealloc {
NSLog(@"销毁了");
}
- (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.candyTreeView];
}
- (void)initSubViewConstraints {
[self.candyTreeView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.top.mas_equalTo(self);
make.height.mas_equalTo(45);
}];
}
- (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;
}
#pragma mark - Getters And Setters
- (void)setCandyInfo:(NSDictionary *)candyInfo {
if (candyInfo) {
NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init];
[attribute appendAttributedString:[self createAttribute:@"厉害了! " color:[UIColor whiteColor]]];
[attribute appendAttributedString:[self createAttribute:candyInfo[@"nick"] color:[ThemeColor messageNickColor]]];
[attribute appendAttributedString:[self createAttribute:@"摘下糖果得 " color:[UIColor whiteColor]]];
[attribute appendAttributedString:[self createAttribute:candyInfo[@"prizeName"] color:[ThemeColor appMainColor]]];
@kWeakify(self);
[self.parser parseWithNamed:@"candyTree_banner" inBundle:[NSBundle mainBundle] completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
@kStrongify(self);
self.candyTreeView.loops = INT_MAX;
self.candyTreeView.clearsAfterStop = NO;
self.candyTreeView.videoItem = videoItem;
[self.candyTreeView setAttributedText:attribute forKey:@"tgs_copywriting"];
[self.candyTreeView startAnimation];
} failureBlock:^(NSError * _Nonnull error) {
}];
}
}
- (SVGAImageView *)candyTreeView {
if (!_candyTreeView) {
_candyTreeView = [[SVGAImageView alloc]init];
_candyTreeView.backgroundColor = [UIColor clearColor];
_candyTreeView.userInteractionEnabled = NO;
}
return _candyTreeView;
}
- (SVGAParser *)parser {
if (!_parser) {
_parser = [[SVGAParser alloc]init];
}
return _parser;
}
@end