修复bug
This commit is contained in:
@@ -1,28 +1,26 @@
|
||||
//
|
||||
// YMRoomCandyGiftView.m
|
||||
// YUMI
|
||||
// XPRoomCandyGiftView.m
|
||||
// xplan-ios
|
||||
//
|
||||
// Created by YUMI on 2021/12/10.
|
||||
// Created by 冯硕 on 2021/12/10.
|
||||
//
|
||||
|
||||
#import "XPRoomCandyGiftView.h"
|
||||
///Third
|
||||
#import <Masonry/Masonry.h>
|
||||
#import <SVGA.h>
|
||||
#import "XPSVGAPlayer.h"
|
||||
#import "YUMIMacroUitls.h"
|
||||
#import "ThemeColor+Room.h"
|
||||
#import "CandyTreeResultModel.h"
|
||||
#import "NSObject+MJExtension.h"
|
||||
|
||||
|
||||
@interface XPRoomCandyGiftView ()
|
||||
///动画管理类
|
||||
@property (strong, nonatomic) SVGAParser *parser;
|
||||
///糖果树特效
|
||||
@property (nonatomic,strong) XPSVGAPlayer *candyTreeView;
|
||||
@property (nonatomic,strong) SVGAImageView *candyTreeView;
|
||||
///背景图
|
||||
@property (nonatomic,strong) UIImageView *backImageView;
|
||||
///容器
|
||||
@property (nonatomic,strong) UIView *titleView;
|
||||
///显示文本内容
|
||||
@property (nonatomic,strong) UILabel *titleLabel;
|
||||
@end
|
||||
@@ -30,134 +28,116 @@
|
||||
@implementation XPRoomCandyGiftView
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame {
|
||||
self = [super initWithFrame:frame];
|
||||
if (self) {
|
||||
[self initSubViews];
|
||||
[self initSubViewConstraints];
|
||||
}
|
||||
return self;
|
||||
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.backImageView addSubview:self.titleView];
|
||||
|
||||
[self.titleView addSubview:self.titleLabel];
|
||||
[self addSubview:self.candyTreeView];
|
||||
[self addSubview:self.backImageView];
|
||||
[self addSubview:self.titleLabel];
|
||||
}
|
||||
|
||||
- (void)initSubViewConstraints {
|
||||
[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) {
|
||||
make.width.mas_equalTo(260);
|
||||
make.height.mas_equalTo(28);
|
||||
make.top.mas_equalTo(self.backImageView).offset(23);
|
||||
make.centerX.mas_equalTo(self.backImageView);
|
||||
}];
|
||||
|
||||
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.right.mas_equalTo(self.titleView);
|
||||
make.centerY.mas_equalTo(self.titleView);
|
||||
}];
|
||||
[self.candyTreeView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.leading.trailing.top.mas_equalTo(self);
|
||||
make.height.mas_equalTo(kGetScaleWidth(55));
|
||||
}];
|
||||
|
||||
[self.backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.leading.trailing.top.mas_equalTo(self.candyTreeView);
|
||||
make.height.mas_equalTo(kGetScaleWidth(55));
|
||||
}];
|
||||
|
||||
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.edges.mas_equalTo(self.backImageView);
|
||||
}];
|
||||
}
|
||||
|
||||
- (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;
|
||||
if(text.length == 0)return nil;
|
||||
NSDictionary * attribute = @{NSFontAttributeName:[UIFont systemFontOfSize:fonSize], NSForegroundColorAttributeName:color};
|
||||
NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:text attributes:attribute];
|
||||
return attr;
|
||||
}
|
||||
|
||||
#pragma mark - Getters And Setters
|
||||
- (void)setCandyInfo:(NSDictionary *)candyInfo {
|
||||
if (candyInfo) {
|
||||
CandyTreeGiftInfoModel * giftInfo = [CandyTreeGiftInfoModel modelWithDictionary:candyInfo];
|
||||
NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init];
|
||||
CGFloat fontSize = self.isMaxLargeGift ? 22 : 13;
|
||||
[attribute appendAttributedString:[self createAttribute:@"厉害了! " color:[UIColor whiteColor] fontSize:fontSize]];
|
||||
[attribute appendAttributedString:[self createAttribute:giftInfo.nick color:[DJDKMIMOMColor colorWithHexString:@"#FEF23E"] fontSize:fontSize]];
|
||||
[attribute appendAttributedString:[self createAttribute:@"摘下糖果得 " color:[UIColor whiteColor] fontSize:fontSize]];
|
||||
[attribute appendAttributedString:[self createAttribute:giftInfo.prizeName color:[DJDKMIMOMColor colorWithHexString:@"#FEF23E"] fontSize:fontSize]];
|
||||
if (giftInfo.prizeNum > 1) {
|
||||
[attribute appendAttributedString:[self createAttribute:[NSString stringWithFormat:@" X%d", giftInfo.prizeNum] color:[UIColor whiteColor] fontSize:fontSize]];
|
||||
}
|
||||
|
||||
NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new];
|
||||
paragraphStyle.lineBreakMode = NSLineBreakByCharWrapping;
|
||||
paragraphStyle.lineSpacing = 4.0f;//行间距
|
||||
paragraphStyle.alignment = NSTextAlignmentCenter;
|
||||
paragraphStyle.baseWritingDirection = NSWritingDirectionLeftToRight;
|
||||
[attribute addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, attribute.length)];
|
||||
[self.candyTreeView setAttributedText:attribute forKey:@"tgs_copywriting"];
|
||||
if (self.isMaxLargeGift) {
|
||||
self.backImageView.hidden = YES;
|
||||
self.candyTreeView.hidden = NO;
|
||||
@kWeakify(self);
|
||||
NSString * anatomiser1Name = [NSString stringWithFormat:@"%@/candyTree_banner.svga", API_Image_URL];
|
||||
[self.parser parseWithURL:[NSURL URLWithString:anatomiser1Name] 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;
|
||||
}
|
||||
}
|
||||
if (candyInfo) {
|
||||
CandyTreeGiftInfoModel * giftInfo = [CandyTreeGiftInfoModel modelWithDictionary:candyInfo];
|
||||
NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init];
|
||||
|
||||
if(giftInfo.nick.length > 5){
|
||||
giftInfo.nick = [NSString stringWithFormat:@"%@...",[giftInfo.nick substringToIndex:5]];
|
||||
}
|
||||
CGFloat fontSize = self.isMaxLargeGift ? 20 : 12;
|
||||
[attribute appendAttributedString:[self createAttribute:YMLocalizedString(@"XPRoomCandyGiftView0") color:[UIColor whiteColor] fontSize:fontSize]];
|
||||
[attribute appendAttributedString:[self createAttribute:giftInfo.nick color:UIColorFromRGB(0xFEF23E) fontSize:fontSize]];
|
||||
[attribute appendAttributedString:[self createAttribute:YMLocalizedString(@"XPRoomCandyGiftView1") color:[UIColor whiteColor] fontSize:fontSize]];
|
||||
[attribute appendAttributedString:[self createAttribute:giftInfo.prizeName color:UIColorFromRGB(0x00EAFF) fontSize:fontSize]];
|
||||
if (giftInfo.prizeNum > 1) {
|
||||
[attribute appendAttributedString:[self createAttribute:[NSString stringWithFormat:@" X%d", giftInfo.prizeNum] color:UIColorFromRGB(0x00EAFF) fontSize:fontSize]];
|
||||
}
|
||||
|
||||
if (self.isMaxLargeGift) {
|
||||
self.backImageView.hidden = YES;
|
||||
self.candyTreeView.hidden = NO;
|
||||
@kWeakify(self);
|
||||
NSString * anatomiser1Name = [NSString stringWithFormat:@"%@/candyTree_banner.svga", API_Image_URL];
|
||||
[self.parser parseWithURL:[NSURL URLWithString:anatomiser1Name] completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
|
||||
@kStrongify(self);
|
||||
self.candyTreeView.loops = 1;
|
||||
self.candyTreeView.clearsAfterStop = NO;
|
||||
self.candyTreeView.videoItem = videoItem;
|
||||
[self.candyTreeView setAttributedText:attribute forKey:@"noble_text_tx"];
|
||||
[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 = NO;
|
||||
}
|
||||
return _candyTreeView;
|
||||
- (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;
|
||||
}
|
||||
|
||||
- (UIView *)titleView {
|
||||
if (!_titleView) {
|
||||
_titleView = [[UIView alloc] init];
|
||||
_titleView.backgroundColor = [UIColor clearColor];
|
||||
}
|
||||
return _titleView;
|
||||
if (!_parser) {
|
||||
_parser = [[SVGAParser alloc]init];
|
||||
}
|
||||
return _parser;
|
||||
}
|
||||
|
||||
- (UIImageView *)backImageView {
|
||||
if (!_backImageView) {
|
||||
_backImageView = [[UIImageView alloc] init];
|
||||
_backImageView.userInteractionEnabled = YES;
|
||||
_backImageView.image = [UIImage imageNamed:@"room_candytree_large_gift_bg"];
|
||||
}
|
||||
return _backImageView;
|
||||
if (!_backImageView) {
|
||||
_backImageView = [[UIImageView alloc] init];
|
||||
_backImageView.userInteractionEnabled = YES;
|
||||
_backImageView.image = [UIImage imageNamed:@"room_candytree_large_gift_bg"];
|
||||
}
|
||||
return _backImageView;
|
||||
}
|
||||
|
||||
- (UILabel *)titleLabel {
|
||||
if (!_titleLabel) {
|
||||
_titleLabel = [[UILabel alloc] init];
|
||||
_titleLabel.numberOfLines = 2;
|
||||
}
|
||||
return _titleLabel;
|
||||
if (!_titleLabel) {
|
||||
_titleLabel = [[UILabel alloc] init];
|
||||
_titleLabel.textAlignment = NSTextAlignmentCenter;
|
||||
}
|
||||
return _titleLabel;
|
||||
}
|
||||
|
||||
@end
|
||||
|
Reference in New Issue
Block a user