Files
peko-ios/YuMi/Modules/YMRoom/View/AnimationView/XPRoomLuckyBigPrizeView.m

127 lines
4.4 KiB
Mathematica
Raw Normal View History

2023-07-06 16:54:13 +08:00
//
// YMRoomLuckyBigPrizeView.m
// YUMI
//
// Created by YUMI on 2022/6/15.
//
2023-07-14 18:50:55 +08:00
#import "XPRoomLuckyBigPrizeView.h"
///Third
2023-07-06 16:54:13 +08:00
#import <Masonry/Masonry.h>
#import "SVGAParser.h"
#import "SVGA.h"
2023-07-14 18:50:55 +08:00
///Tool
2023-07-06 16:54:13 +08:00
#import "DJDKMIMOMColor.h"
#import "YUMIMacroUitls.h"
2023-07-14 18:50:55 +08:00
///Model
#import "XPGiftBigPrizeModel.h"
///View
#import "XPSVGAPlayer.h"
2023-07-06 16:54:13 +08:00
2023-07-14 18:50:55 +08:00
@interface XPRoomLuckyBigPrizeView ()
///
@property (strong, nonatomic) SVGAParser *parser;
@property (nonatomic, strong) XPSVGAPlayer *giftImageView;
2023-07-06 16:54:13 +08:00
@end
2023-07-14 18:50:55 +08:00
@implementation XPRoomLuckyBigPrizeView
2023-07-06 16:54:13 +08:00
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self initSubViews];
2023-07-14 18:50:55 +08:00
[self initSubViewConstraints];
2023-07-06 16:54:13 +08:00
}
return self;
}
#pragma mark - Private Method
- (void)initSubViews {
2023-07-14 18:50:55 +08:00
[self addSubview:self.giftImageView];
2023-07-06 16:54:13 +08:00
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapRecognizer:)];
[self addGestureRecognizer:tap];
}
2023-07-14 18:50:55 +08:00
- (void)initSubViewConstraints {
[self.giftImageView mas_makeConstraints:^(MASConstraintMaker *make) {
2023-07-06 16:54:13 +08:00
make.edges.mas_equalTo(self);
}];
}
#pragma mark - Event Response
- (void)tapRecognizer:(UITapGestureRecognizer *)tap {
2023-07-14 18:50:55 +08:00
if (self.delegate && [self.delegate respondsToSelector:@selector(xPRoomLuckyBigPrizeView:luckyGiftInfo:)]) {
[self.delegate xPRoomLuckyBigPrizeView:self luckyGiftInfo:self.giftInfo];
2023-07-06 16:54:13 +08:00
}
}
#pragma mark - Getters And Setters
2023-07-14 18:50:55 +08:00
- (void)setGiftInfo:(PIBaseAnimationViewModel*)giftInfo {
2023-07-06 16:54:13 +08:00
_giftInfo = giftInfo;
if (_giftInfo) {
NSString * nick = _giftInfo.nick;
if (nick.length > 6) {
nick = [nick substringToIndex:6];
}
CGFloat fontSize = 22;
NSDictionary * dic = @{NSFontAttributeName:[UIFont systemFontOfSize:fontSize], NSForegroundColorAttributeName:[UIColor whiteColor]};
2023-07-14 18:50:55 +08:00
NSDictionary * mainDic = @{NSFontAttributeName:[UIFont systemFontOfSize:fontSize], NSForegroundColorAttributeName:[DJDKMIMOMColor appMainColor]};
2023-07-06 16:54:13 +08:00
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] init];
[attributedString appendAttributedString:[[NSMutableAttributedString alloc] initWithString:@"恭喜 " attributes:dic]];
if (nick) {
[attributedString appendAttributedString:[[NSMutableAttributedString alloc] initWithString:nick attributes:mainDic]];
}
2023-07-14 18:50:55 +08:00
[attributedString appendAttributedString:[[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:YMLocalizedString(@"XPRoomLuckyBigPrizeView1"),_giftInfo.luckyBagName] attributes:dic]];
2023-07-06 16:54:13 +08:00
if (giftInfo.goldPrice) {
[attributedString appendAttributedString:[[NSMutableAttributedString alloc] initWithString:giftInfo.goldPrice attributes:mainDic]];
}
[attributedString appendAttributedString:[[NSMutableAttributedString alloc] initWithString:giftInfo.giftName attributes:mainDic]];
NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new];
paragraphStyle.lineBreakMode = NSLineBreakByCharWrapping;
paragraphStyle.alignment = NSTextAlignmentLeft;
2023-07-14 18:50:55 +08:00
paragraphStyle.lineSpacing = 4.0f;//
// ()
2023-07-06 16:54:13 +08:00
paragraphStyle.alignment = NSTextAlignmentLeft;
paragraphStyle.baseWritingDirection = NSWritingDirectionLeftToRight;
[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, attributedString.length)];
if (_giftInfo.isInRoomVisiable) {
2023-07-14 18:50:55 +08:00
[self.giftImageView setHidden:YES forKey:@"img_206"];
2023-07-06 16:54:13 +08:00
} else {
2023-07-14 18:50:55 +08:00
[self.giftImageView setHidden:NO forKey:@"img_206"];
2023-07-06 16:54:13 +08:00
}
@kWeakify(self);
2023-07-14 18:50:55 +08:00
[self.giftImageView setAttributedText:attributedString forKey:@"fdpp_copywriting"];
2023-07-06 16:54:13 +08:00
NSString * anatomiser1Name = [NSString stringWithFormat:@"%@/lucky_gift_streamer.svga", API_Image_URL];
2023-07-14 18:50:55 +08:00
[self.parser parseWithURL:[NSURL URLWithString:anatomiser1Name] completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
2023-07-06 16:54:13 +08:00
@kStrongify(self);
self.hidden = NO;
2023-07-14 18:50:55 +08:00
self.giftImageView.hidden = NO;
self.giftImageView.videoItem = videoItem;
self.giftImageView.loops = 1;
self.giftImageView.clearsAfterStop = YES;
[self.giftImageView startAnimation];
2023-07-06 16:54:13 +08:00
} failureBlock:^(NSError * _Nonnull error) {
}];
}
}
2023-07-14 18:50:55 +08:00
- (XPSVGAPlayer *)giftImageView {
if (!_giftImageView) {
_giftImageView = [[XPSVGAPlayer alloc]init];
_giftImageView.backgroundColor = [UIColor clearColor];
_giftImageView.userInteractionEnabled = NO;
2023-07-06 16:54:13 +08:00
}
2023-07-14 18:50:55 +08:00
return _giftImageView;
2023-07-06 16:54:13 +08:00
}
2023-07-14 18:50:55 +08:00
- (SVGAParser *)parser {
if (!_parser) {
_parser = [[SVGAParser alloc]init];
2023-07-06 16:54:13 +08:00
}
2023-07-14 18:50:55 +08:00
return _parser;
2023-07-06 16:54:13 +08:00
}
@end