192 lines
7.1 KiB
Objective-C
192 lines
7.1 KiB
Objective-C
//
|
||
// 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) {
|
||
return model;
|
||
}
|
||
|
||
BravoGiftWinningFlagView *flagView = [[BravoGiftWinningFlagView alloc] init];
|
||
flagView.model = model;
|
||
flagView.alpha = 0;
|
||
flagView.frame = CGRectMake(0, 0, kGetScaleWidth(274), kGetScaleWidth(216));
|
||
|
||
// 🔧 修复:重新计算位置,确保视图在屏幕可见范围内
|
||
CGFloat viewWidth = kGetScaleWidth(274);
|
||
CGFloat viewHeight = kGetScaleWidth(216);
|
||
CGFloat screenWidth = KScreenWidth;
|
||
CGFloat screenHeight = KScreenHeight;
|
||
|
||
// 计算安全的 Y 位置:屏幕高度的 40% 位置
|
||
CGFloat safeY = screenHeight * 0.4;
|
||
|
||
// 确保视图不会超出屏幕边界
|
||
CGFloat maxY = screenHeight - viewHeight/2 - 20; // 留20点边距
|
||
CGFloat minY = viewHeight/2 + 20; // 留20点边距
|
||
CGFloat finalY = MAX(minY, MIN(safeY, maxY));
|
||
|
||
flagView.center = CGPointMake(screenWidth/2, finalY);
|
||
flagView.transform = CGAffineTransformMakeScale(0.1, 0.1);
|
||
|
||
NSLog(@"🎯 BravoGiftWinningFlagView: 位置计算 - screenSize: %.0fx%.0f, viewSize: %.0fx%.0f, center: (%.0f, %.0f)",
|
||
screenWidth, screenHeight, viewWidth, viewHeight, flagView.center.x, flagView.center.y);
|
||
|
||
[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
|