126 lines
4.3 KiB
Objective-C
126 lines
4.3 KiB
Objective-C
//
|
|
// XPRoomLuckyBigPrizeView.m
|
|
// xplan-ios
|
|
//
|
|
// Created by 冯硕 on 2022/6/15.
|
|
//
|
|
|
|
#import "XPRoomLuckyBigPrizeView.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
#import "SVGAParser.h"
|
|
#import "SVGA.h"
|
|
///Tool
|
|
#import "ThemeColor.h"
|
|
#import "XPMacro.h"
|
|
///Model
|
|
#import "XPGiftBigPrizeModel.h"
|
|
///View
|
|
#import "XPSVGAPlayer.h"
|
|
|
|
|
|
@interface XPRoomLuckyBigPrizeView ()
|
|
///动画管理类
|
|
@property (strong, nonatomic) SVGAParser *parser;
|
|
@property (nonatomic, strong) XPSVGAPlayer *giftImageView;
|
|
@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.giftImageView];
|
|
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapRecognizer:)];
|
|
[self addGestureRecognizer:tap];
|
|
}
|
|
|
|
- (void)initSubViewConstraints {
|
|
[self.giftImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.edges.mas_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];
|
|
}
|
|
}
|
|
|
|
#pragma mark - Getters And Setters
|
|
- (void)setGiftInfo:(XPGiftBigPrizeModel *)giftInfo {
|
|
_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]};
|
|
NSDictionary * mainDic = @{NSFontAttributeName:[UIFont systemFontOfSize:fontSize], NSForegroundColorAttributeName:[ThemeColor appMainColor]};
|
|
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] init];
|
|
[attributedString appendAttributedString:[[NSMutableAttributedString alloc] initWithString:@"恭喜 " attributes:dic]];
|
|
if (nick) {
|
|
[attributedString appendAttributedString:[[NSMutableAttributedString alloc] initWithString:nick attributes:mainDic]];
|
|
}
|
|
|
|
[attributedString appendAttributedString:[[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"在%@幸运礼物中欧气爆棚开出了价值",_giftInfo.luckyBagName] attributes:dic]];
|
|
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;
|
|
paragraphStyle.lineSpacing = 4.0f;//行间距
|
|
// 强制排版(从左到右)
|
|
paragraphStyle.alignment = NSTextAlignmentLeft;
|
|
paragraphStyle.baseWritingDirection = NSWritingDirectionLeftToRight;
|
|
[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, attributedString.length)];
|
|
if (_giftInfo.isInRoomVisiable) {
|
|
[self.giftImageView setHidden:YES forKey:@"img_206"];
|
|
} else {
|
|
[self.giftImageView setHidden:NO forKey:@"img_206"];
|
|
}
|
|
@kWeakify(self);
|
|
[self.giftImageView setAttributedText:attributedString forKey:@"fdpp_copywriting"];
|
|
[self.parser parseWithNamed:@"lucky_gift_streamer" inBundle:[NSBundle mainBundle] completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
|
|
@kStrongify(self);
|
|
self.hidden = NO;
|
|
self.giftImageView.hidden = NO;
|
|
self.giftImageView.videoItem = videoItem;
|
|
self.giftImageView.loops = 1;
|
|
self.giftImageView.clearsAfterStop = YES;
|
|
[self.giftImageView startAnimation];
|
|
} failureBlock:^(NSError * _Nonnull error) {
|
|
|
|
}];
|
|
}
|
|
}
|
|
|
|
- (XPSVGAPlayer *)giftImageView {
|
|
if (!_giftImageView) {
|
|
_giftImageView = [[XPSVGAPlayer alloc]init];
|
|
_giftImageView.backgroundColor = [UIColor clearColor];
|
|
_giftImageView.userInteractionEnabled = NO;
|
|
}
|
|
return _giftImageView;
|
|
}
|
|
|
|
- (SVGAParser *)parser {
|
|
if (!_parser) {
|
|
_parser = [[SVGAParser alloc]init];
|
|
}
|
|
return _parser;
|
|
}
|
|
@end
|