87 lines
2.6 KiB
Objective-C
87 lines
2.6 KiB
Objective-C
//
|
|
// 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
|
|
|
|
- (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 = 1;
|
|
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
|