Files
peko-ios/YuMi/Modules/YMRoom/View/AnimationView/BravoGiftWinningFlagView.m
AI Health Developer 40311a1d85 完成 1.0.26 需求
2025-04-21 13:52:13 +08:00

173 lines
6.3 KiB
Objective-C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// BravoGiftWinningFlagView.m
// YuMi
//
// Created by P on 2025/3/25.
//
#import "BravoGiftWinningFlagView.h"
#import "MoliMoneyLabel.h"
#import "AttachmentModel.h"
//{"data":"{\"uid\":3224,\"receiverUidList\":[3224],\"roomUid\":3184,\"tip\":{\"times\":\"0.70\",\"coins\":\"700.0\",\"level\":1},\"receiverProfit\":\"50.00\",\"roomId\":6076861580}","first":106,"second":1065}
@implementation BravoGiftWinningFlagViewModel
@end
@interface BravoGiftWinningFlagView ()
@property (nonatomic, strong) BravoGiftWinningFlagViewModel *model;
@property (nonatomic, strong) UIImageView *backgroundImageView;
//@property (nonatomic, strong) MoliMoneyLabel *moneyLabel;
@property (nonatomic, strong) UILabel *moneyLabel_2;
@property (nonatomic, strong) UILabel *timesLabel;
@end
@implementation BravoGiftWinningFlagView
+ (BravoGiftWinningFlagViewModel *)display:(UIView *)superView with:(AttachmentModel *)attachment roomID:(NSInteger)roomID uID:(NSString *)UID {
BravoGiftWinningFlagViewModel *model = [BravoGiftWinningFlagViewModel modelWithJSON:attachment.data];
if (model.roomId != roomID || model.uid != UID.integerValue || model.tip == nil) {
return model;
}
BravoGiftWinningFlagView *flagView = [[BravoGiftWinningFlagView alloc] init];
flagView.model = model;
flagView.alpha = 0;
flagView.frame = CGRectMake(0, 0, kGetScaleWidth(274), kGetScaleWidth(216));
flagView.center = CGPointMake(superView.center.x, kGetScaleWidth(216) + kGetScaleWidth(216)/2 - 40);
flagView.transform = CGAffineTransformMakeScale(0.1, 0.1);
[superView addSubview:flagView];
// 使用弹簧动画执行放大动画alpha从0变为1带有弹性效果
[UIView animateWithDuration:0.8
delay:0
usingSpringWithDamping:0.3 // 弹性系数,数值越小弹性越强
initialSpringVelocity:0.5 // 初始速度
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
flagView.alpha = 1.0;
flagView.transform = CGAffineTransformMakeScale(1.0, 1.0); // 还原为正常大小
} completion:^(BOOL finished) {
// 动画完成后等待2秒再执行反向动画
[UIView animateWithDuration:0.5
delay:2.0 // 延迟2秒执行反向动画
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
flagView.alpha = 0.0;
flagView.transform = CGAffineTransformMakeScale(0.1, 0.1); // 缩小回原始大小
} completion:^(BOOL finished) {
// 动画完成后移除 view
[flagView removeFromSuperview];
}];
}];
return model;
}
- (instancetype)init
{
self = [super init];
if (self) {
[self setupUI];
}
return self;
}
- (void)setupUI {
[self addSubview:self.backgroundImageView];
[self.backgroundImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self);
}];
[self addSubview:self.moneyLabel_2];
[self.moneyLabel_2 mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self);
make.bottom.mas_equalTo(-70);
make.height.mas_equalTo(24);
}];
UIStackView *stackView = [[UIStackView alloc] initWithArrangedSubviews:@[
[self winLabel],
self.timesLabel
]];
stackView.spacing = 4;
stackView.alignment = UIStackViewAlignmentCenter;
[self addSubview:stackView];
[stackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self);
make.bottom.mas_equalTo(-48);
}];
[self.timesLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(10);
}];
}
- (void)setModel:(BravoGiftWinningFlagViewModel *)model {
NSNumber *level = [model.tip objectForKey:@"level"];
NSString *times = [model.tip objectForKey:@"times"];
NSNumber *coins = [model.tip objectForKey:@"coins"];
// [self.moneyLabel updateContent:coins.stringValue];
self.backgroundImageView.image = level.integerValue >= 3 ? kImage(@"brove_tips_high") : kImage(@"brove_tips_low");
self.timesLabel.text = [NSString stringWithFormat:@"%@ %@", [NSString stringByRemovingRedundantZeros:times], YMLocalizedString(@"Combo_9")];
NSTextAttachment *moneyIcon = [[NSTextAttachment alloc] init];
moneyIcon.image = kImage(@"moli_money_icon");
NSMutableAttributedString *money = [[NSMutableAttributedString alloc] initWithString:[NSString stringByRemovingRedundantZeros:coins.stringValue] attributes:@{
NSFontAttributeName: kFontMedium(26),
NSForegroundColorAttributeName: UIColorFromRGB(0xffe169)
}];
[money appendAttributedString:[NSAttributedString attributedStringWithAttachment:moneyIcon]];
self.moneyLabel_2.attributedText = money.copy;
}
- (UIImageView *)backgroundImageView {
if (!_backgroundImageView) {
_backgroundImageView = [[UIImageView alloc] init];//WithImage:kImage(@"brove_tips_high")];
_backgroundImageView.contentMode = UIViewContentModeScaleAspectFit;
}
return _backgroundImageView;
}
//- (MoliMoneyLabel *)moneyLabel {
// if (!_moneyLabel) {
// _moneyLabel = [MoliMoneyLabel moneyLabelWithTextColot:UIColorFromRGB(0xFFE169)
// font:kFontMedium(26)
// moneyPostion:2
// moneySize:CGSizeMake(24, 24)];
// [_moneyLabel removeSpace];
// [_moneyLabel updateSpacing:0];
// [_moneyLabel updateLabelAlignment:NSTextAlignmentRight];
// [_moneyLabel insertSpaceAtLeast];
//
// }
// return _moneyLabel;
//}
- (UILabel *)moneyLabel_2 {
if (!_moneyLabel_2) {
_moneyLabel_2 = [[UILabel alloc] init];
}
return _moneyLabel_2;
}
- (UILabel *)winLabel {
return [UILabel labelInitWithText:YMLocalizedString(@"Combo_4")
font:kFontRegular(13)
textColor:[UIColor whiteColor]];
}
- (UILabel *)timesLabel {
if (!_timesLabel) {
_timesLabel = [UILabel labelInitWithText:@""
font:kFontMedium(13)
textColor:UIColorFromRGB(0xFFE169)];
}
return _timesLabel;
}
@end