177 lines
6.2 KiB
Objective-C
177 lines
6.2 KiB
Objective-C
//
|
|
// YMRoomLuckyBigPrizeView.m
|
|
// YUMI
|
|
//
|
|
// Created by YUMI on 2022/6/15.
|
|
//
|
|
|
|
#import "XPRoomLuckyBigPrizeView.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
#import "SVGAParser.h"
|
|
#import "SVGA.h"
|
|
///Tool
|
|
#import "DJDKMIMOMColor.h"
|
|
#import "YUMIMacroUitls.h"
|
|
///Model
|
|
#import "XPGiftBigPrizeModel.h"
|
|
///View
|
|
#import "XPSVGAPlayer.h"
|
|
|
|
|
|
@interface XPRoomLuckyBigPrizeView ()<SVGAPlayerDelegate>
|
|
///动画管理类
|
|
@property (strong, nonatomic) SVGAParser *parser;
|
|
@property (nonatomic, strong) XPSVGAPlayer *giftSvgaView;
|
|
@property(nonatomic,strong) NetImageView *chestImageView;
|
|
@property(nonatomic,strong) NetImageView *giftImageView;
|
|
@property(nonatomic,strong) UILabel *contentView;
|
|
@end
|
|
|
|
@implementation XPRoomLuckyBigPrizeView
|
|
|
|
- (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.giftSvgaView];
|
|
[self addSubview:self.chestImageView];
|
|
[self addSubview:self.giftImageView];
|
|
[self addSubview:self.contentView];
|
|
|
|
}
|
|
|
|
- (void)initSubViewConstraints {
|
|
[self.giftSvgaView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.edges.mas_equalTo(self);
|
|
}];
|
|
[self.chestImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.mas_equalTo(9);
|
|
make.centerY.equalTo(self);
|
|
make.height.width.mas_equalTo(60);
|
|
}];
|
|
[self.giftImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.trailing.mas_equalTo(-9);
|
|
make.centerY.equalTo(self);
|
|
make.height.width.mas_equalTo(60);
|
|
}];
|
|
[self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.trailing.equalTo(self).inset(69);
|
|
make.centerY.equalTo(self);
|
|
}];
|
|
}
|
|
|
|
#pragma mark - Event Response
|
|
- (void)tapRecognizer:(UITapGestureRecognizer *)tap {
|
|
if (self.delegate && [self.delegate respondsToSelector:@selector(xPRoomLuckyBigPrizeView:luckyGiftInfo:)]) {
|
|
[self.delegate xPRoomLuckyBigPrizeView:self luckyGiftInfo:self.giftInfo];
|
|
}
|
|
}
|
|
- (void)chestImageViewTapRecognizer:(UITapGestureRecognizer *)tap{
|
|
[self tapRecognizer:tap];
|
|
}
|
|
- (void)giftImageViewTapRecognizer:(UITapGestureRecognizer *)tap{
|
|
[self tapRecognizer:tap];
|
|
}
|
|
#pragma mark - Getters And Setters
|
|
- (void)setGiftInfo:(PIBaseAnimationViewModel*)giftInfo {
|
|
_giftInfo = giftInfo;
|
|
if (_giftInfo) {
|
|
NSString * nick = _giftInfo.nick ?: @"";
|
|
if (nick.length > 5) {
|
|
nick = [nick substringToIndex:5];
|
|
}
|
|
NSString *goldPrice = _giftInfo.goldPrice ?: @"0";
|
|
NSString *giftName = _giftInfo.giftName ?: @"";
|
|
NSString *luckyBagName = _giftInfo.luckyBagName ?: @"";
|
|
NSString *giftNum = _giftInfo.giftNum ?: @"0";
|
|
NSString *mainText = [NSString stringWithFormat:YMLocalizedString(@"XPRoomLuckyBigPrizeView0"),nick,luckyBagName,goldPrice,giftName];
|
|
if([giftNum integerValue] > 1){
|
|
mainText = [NSString stringWithFormat:@"%@ X%@",mainText,giftNum];
|
|
}
|
|
CGFloat fontSize = 12;
|
|
NSDictionary * dic = @{NSFontAttributeName:[UIFont systemFontOfSize:fontSize weight:UIFontWeightMedium], NSForegroundColorAttributeName:UIColorFromRGB(0xFFF45E)};
|
|
NSDictionary * mainDic = @{NSFontAttributeName:[UIFont systemFontOfSize:fontSize weight:UIFontWeightMedium], NSForegroundColorAttributeName:[UIColor whiteColor]};
|
|
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] init];
|
|
[attributedString appendAttributedString:[[NSMutableAttributedString alloc] initWithString:mainText attributes:mainDic]];
|
|
|
|
[attributedString addAttributes:dic range:[mainText rangeOfString:nick]];
|
|
[attributedString addAttributes:dic range:[mainText rangeOfString:luckyBagName]];
|
|
[attributedString addAttributes:dic range:[mainText rangeOfString:goldPrice]];
|
|
[attributedString addAttributes:dic range:[mainText rangeOfString:giftName]];
|
|
if([giftNum integerValue] > 1){
|
|
[attributedString addAttributes:dic range:[mainText rangeOfString:giftNum]];
|
|
}
|
|
_contentView.attributedText = attributedString;
|
|
_chestImageView.imageUrl = _giftInfo.luckyBagGiftPic;
|
|
_giftImageView.imageUrl = _giftInfo.giftPic;
|
|
@kWeakify(self);
|
|
|
|
[self.parser parseWithNamed:@"pi_room_lucky_gift" inBundle:nil completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
|
|
@kStrongify(self);
|
|
self.hidden = NO;
|
|
self.giftSvgaView.hidden = NO;
|
|
self.giftSvgaView.videoItem = videoItem;
|
|
self.giftSvgaView.loops = 10000;
|
|
self.giftSvgaView.clearsAfterStop = YES;
|
|
[self.giftSvgaView startAnimation];
|
|
} failureBlock:^(NSError * _Nullable error) {
|
|
}];
|
|
|
|
|
|
}
|
|
}
|
|
- (void)svgaPlayerDidFinishedAnimation:(SVGAPlayer *)player{
|
|
NSLog(@"11111");
|
|
}
|
|
- (XPSVGAPlayer *)giftSvgaView {
|
|
if (!_giftSvgaView) {
|
|
_giftSvgaView = [[XPSVGAPlayer alloc]init];
|
|
_giftSvgaView.backgroundColor = [UIColor clearColor];
|
|
_giftSvgaView.userInteractionEnabled = NO;
|
|
_giftSvgaView.delegate = self;
|
|
}
|
|
return _giftSvgaView;
|
|
}
|
|
|
|
- (SVGAParser *)parser {
|
|
if (!_parser) {
|
|
_parser = [[SVGAParser alloc]init];
|
|
}
|
|
return _parser;
|
|
}
|
|
- (NetImageView *)chestImageView{
|
|
if(!_chestImageView){
|
|
_chestImageView = [NetImageView new];
|
|
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(chestImageViewTapRecognizer:)];
|
|
_chestImageView.userInteractionEnabled = YES;
|
|
[_chestImageView addGestureRecognizer:tap];
|
|
}
|
|
return _chestImageView;
|
|
}
|
|
- (NetImageView *)giftImageView{
|
|
if(!_giftImageView){
|
|
_giftImageView = [NetImageView new];
|
|
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(giftImageViewTapRecognizer:)];
|
|
_giftImageView.userInteractionEnabled = YES;
|
|
[_giftImageView addGestureRecognizer:tap];
|
|
}
|
|
return _giftImageView;
|
|
}
|
|
- (UILabel *)contentView{
|
|
if(!_contentView){
|
|
_contentView = [UILabel labelInitWithText:@"" font:kFontMedium(10) textColor:[UIColor whiteColor]];
|
|
_contentView.textAlignment = NSTextAlignmentCenter;
|
|
_contentView.numberOfLines = 2;
|
|
}
|
|
return _contentView;
|
|
}
|
|
@end
|