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

192 lines
6.5 KiB
Mathematica
Raw Normal View History

2023-02-13 18:15:19 +08:00
//
// XPStarredKitchenGiftView.m
// xplan-ios
//
// Created by on 2023/2/13.
//
///
#import "XPStarredKitchenGiftView.h"
///Third
#import <Masonry/Masonry.h>
#import <SVGA.h>
#import "XPSVGAPlayer.h"
#import "XPMacro.h"
#import "ThemeColor+Room.h"
#import "XPStarredKitchenModel.h"
#import "NSObject+MJExtension.h"
#import "XCCurrentVCStackManager.h"
#import "XPWebViewController.h"
@interface XPStarredKitchenGiftView ()
///
@property (strong, nonatomic) SVGAParser *parser;
///
@property (nonatomic,strong) XPSVGAPlayer *candyTreeView;
///
@property (nonatomic,strong) UIImageView *backImageView;
///
@property (nonatomic,strong) UIView *titleView;
///
@property (nonatomic,strong) UILabel *titleLabel;
///
@property (nonatomic,strong) XPStarredKitchenModel *kitchenModel;
///
@property (nonatomic,strong) UIButton *actionButton;
@end
@implementation XPStarredKitchenGiftView
- (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];
[self addSubview:self.backImageView];
[self addSubview:self.actionButton];
[self.backImageView addSubview:self.titleView];
[self.titleView addSubview:self.titleLabel];
}
- (void)recognizer {
if (self.delegate && [self.delegate respondsToSelector:@selector(xPStarredKitchenGiftView:didClickEnter:)]) {
[self.delegate xPStarredKitchenGiftView:self didClickEnter:self.kitchenModel];
}
}
- (void)initSubViewConstraints {
[self.actionButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self);
}];
[self.candyTreeView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self);
}];
[self.backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self);
}];
[self.titleView mas_makeConstraints:^(MASConstraintMaker *make) {
2023-03-21 19:30:33 +08:00
make.height.mas_equalTo(33);
make.top.mas_equalTo(self.backImageView).offset(19);
make.left.mas_equalTo(self.backImageView).offset(85);
make.right.mas_equalTo(self.backImageView).offset(-53);
2023-02-13 18:15:19 +08:00
}];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.mas_equalTo(self.titleView);
make.centerY.mas_equalTo(self.titleView);
}];
}
- (NSAttributedString *)createAttribute:(NSString * )text color:(UIColor *)color fontSize:(CGFloat)fonSize {
NSDictionary * attribute = @{NSFontAttributeName:[UIFont systemFontOfSize:fonSize], NSForegroundColorAttributeName:color};
NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:text attributes:attribute];
return attr;
}
#pragma mark - Getters And Setters
- (void)setStarredKitchenDic:(NSDictionary *)starredKitchenDic{
if (starredKitchenDic) {
XPStarredKitchenModel * giftInfo = [XPStarredKitchenModel modelWithDictionary:starredKitchenDic];
self.kitchenModel = giftInfo;
NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init];
CGFloat fontSize = self.isMaxLargeGift ? 22 : 13;
[attribute appendAttributedString:[self createAttribute:@"恭喜" color:[UIColor whiteColor] fontSize:fontSize]];
NSString * nick = giftInfo.nick;
if (nick.length > 6) {
nick = [nick substringToIndex:6];
}
[attribute appendAttributedString:[self createAttribute:nick color:[ThemeColor colorWithHexString:@"#FEF23E"] fontSize:fontSize]];
2023-03-21 19:30:33 +08:00
[attribute appendAttributedString:[self createAttribute:@"在深海奇缘抽中 " color:[UIColor whiteColor] fontSize:fontSize]];
2023-02-13 18:15:19 +08:00
[attribute appendAttributedString:[self createAttribute:[NSString stringWithFormat:@"%ld", giftInfo.itemMultiple] color:[ThemeColor colorWithHexString:@"#00EAFF"] fontSize:fontSize]];
[attribute appendAttributedString:[self createAttribute:@"倍奖励,获得" color:[ThemeColor colorWithHexString:@"#FEF23E"] fontSize:fontSize]];
[attribute appendAttributedString:[self createAttribute:[NSString stringWithFormat:@" %ld", giftInfo.diamonds] color:[ThemeColor colorWithHexString:@"#00EAFF"] fontSize:fontSize]];
[attribute appendAttributedString:[self createAttribute:@"钻石" color:[UIColor whiteColor] fontSize:fontSize]];
NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new];
paragraphStyle.lineBreakMode = NSLineBreakByCharWrapping;
2023-03-21 19:30:33 +08:00
paragraphStyle.lineSpacing = 0.0f;//
2023-02-13 18:15:19 +08:00
paragraphStyle.alignment = NSTextAlignmentCenter;
paragraphStyle.baseWritingDirection = NSWritingDirectionLeftToRight;
[attribute addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, attribute.length)];
[self.candyTreeView setAttributedText:attribute forKey:@"noble_text_tx"];
if (self.isMaxLargeGift) {
self.backImageView.hidden = YES;
self.candyTreeView.hidden = NO;
@kWeakify(self);
[self.parser parseWithNamed:@"starred_kitchen_bg" inBundle:[NSBundle mainBundle] completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
@kStrongify(self);
self.candyTreeView.loops = 1;
self.candyTreeView.clearsAfterStop = NO;
self.candyTreeView.videoItem = videoItem;
[self.candyTreeView startAnimation];
} failureBlock:^(NSError * _Nonnull error) {
}];
} else {
self.backImageView.hidden = NO;
self.candyTreeView.hidden = YES;
self.titleLabel.attributedText = attribute;
self.titleLabel.textAlignment = NSTextAlignmentCenter;
}
}
}
- (XPSVGAPlayer *)candyTreeView {
if (!_candyTreeView) {
_candyTreeView = [[XPSVGAPlayer alloc]init];
_candyTreeView.backgroundColor = [UIColor clearColor];
_candyTreeView.userInteractionEnabled = YES;
}
return _candyTreeView;
}
- (SVGAParser *)parser {
if (!_parser) {
_parser = [[SVGAParser alloc]init];
}
return _parser;
}
- (UIView *)titleView {
if (!_titleView) {
_titleView = [[UIView alloc] init];
_titleView.backgroundColor = [UIColor clearColor];
}
return _titleView;
}
- (UIImageView *)backImageView {
if (!_backImageView) {
_backImageView = [[UIImageView alloc] init];
_backImageView.userInteractionEnabled = YES;
_backImageView.image = [UIImage imageNamed:@"room_starred_kitchen_large_gift_bg"];
}
return _backImageView;
}
- (UILabel *)titleLabel {
if (!_titleLabel) {
_titleLabel = [[UILabel alloc] init];
_titleLabel.numberOfLines = 2;
}
return _titleLabel;
}
- (UIButton *)actionButton {
if (!_actionButton) {
_actionButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_actionButton addTarget:self action:@selector(recognizer) forControlEvents:UIControlEventTouchUpInside];
}
return _actionButton;
}
@end