197 lines
6.4 KiB
Objective-C
197 lines
6.4 KiB
Objective-C
//
|
||
// LuckyGiftWinningFlagView.m
|
||
// YuMi
|
||
//
|
||
// Created by P on 2024/9/10.
|
||
//
|
||
|
||
#import "LuckyGiftWinningFlagView.h"
|
||
#import "AttachmentModel.h"
|
||
|
||
@interface LuckyGiftWinningFlagViewModel : PIBaseModel
|
||
|
||
@property (nonatomic, assign) NSInteger uid;
|
||
@property (nonatomic, assign) NSInteger level;
|
||
@property (nonatomic, assign) NSInteger roomId;
|
||
|
||
@property (nonatomic, copy) NSString *times;
|
||
@property (nonatomic, copy) NSString *coins;
|
||
@property (nonatomic, copy) NSString *roomUid;
|
||
|
||
@end
|
||
|
||
|
||
@implementation LuckyGiftWinningFlagViewModel
|
||
|
||
@end
|
||
|
||
@interface LuckyGiftWinningFlagView ()
|
||
|
||
@property (nonatomic, strong) LuckyGiftWinningFlagViewModel *model;
|
||
|
||
@property (nonatomic, strong) UILabel *winLabel;
|
||
@property (nonatomic, strong) UILabel *winPriceLabel;
|
||
@property (nonatomic, strong) UILabel *winTimesLabel;
|
||
|
||
@property (nonatomic, strong) UIImageView *coinIcon;
|
||
@property (nonatomic, strong) UIImageView *backgroundImageView;
|
||
|
||
@end
|
||
|
||
@implementation LuckyGiftWinningFlagView
|
||
|
||
+ (void)display:(UIView *)superView
|
||
with:(AttachmentModel *)attachment
|
||
roomID:(NSInteger)roomID
|
||
uID:(NSString *)UID
|
||
{
|
||
LuckyGiftWinningFlagViewModel *model = [LuckyGiftWinningFlagViewModel modelWithDictionary:attachment.data];
|
||
if (model.roomId != roomID || model.uid != UID.integerValue) {
|
||
return;
|
||
}
|
||
|
||
LuckyGiftWinningFlagView *winningFlagView = [[LuckyGiftWinningFlagView alloc] init];
|
||
winningFlagView.model = model;
|
||
winningFlagView.alpha = 0;
|
||
winningFlagView.frame = CGRectMake(0, 0, kGetScaleWidth(162), kGetScaleWidth(162));
|
||
winningFlagView.center = CGPointMake(superView.center.x, kGetScaleWidth(163) + kGetScaleWidth(162)/2);
|
||
winningFlagView.transform = CGAffineTransformMakeScale(0.1, 0.1);
|
||
[superView addSubview:winningFlagView];
|
||
|
||
// 使用弹簧动画执行放大动画,alpha从0变为1,带有弹性效果
|
||
[UIView animateWithDuration:0.8
|
||
delay:0
|
||
usingSpringWithDamping:0.3 // 弹性系数,数值越小弹性越强
|
||
initialSpringVelocity:0.5 // 初始速度
|
||
options:UIViewAnimationOptionCurveEaseInOut
|
||
animations:^{
|
||
winningFlagView.alpha = 1.0;
|
||
winningFlagView.transform = CGAffineTransformMakeScale(1.0, 1.0); // 还原为正常大小
|
||
} completion:^(BOOL finished) {
|
||
// 动画完成后,等待2秒再执行反向动画
|
||
[UIView animateWithDuration:0.5
|
||
delay:2.0 // 延迟2秒执行反向动画
|
||
options:UIViewAnimationOptionCurveEaseInOut
|
||
animations:^{
|
||
winningFlagView.alpha = 0.0;
|
||
winningFlagView.transform = CGAffineTransformMakeScale(0.1, 0.1); // 缩小回原始大小
|
||
} completion:^(BOOL finished) {
|
||
// 动画完成后移除 view
|
||
[winningFlagView removeFromSuperview];
|
||
}];
|
||
}];
|
||
}
|
||
|
||
- (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.winLabel];
|
||
[self.winLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.centerX.mas_equalTo(self);
|
||
make.top.mas_equalTo(kGetScaleWidth(40));
|
||
}];
|
||
|
||
UIStackView *stackView = [[UIStackView alloc] init];
|
||
stackView.spacing = 6;
|
||
[self addSubview:stackView];
|
||
[stackView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.centerX.mas_equalTo(self.backgroundImageView);
|
||
make.top.mas_equalTo(self.winLabel.mas_bottom).offset(11);
|
||
make.height.mas_equalTo(35);
|
||
}];
|
||
|
||
[stackView addArrangedSubview:self.coinIcon];
|
||
[stackView addArrangedSubview:self.winPriceLabel];
|
||
|
||
[self.coinIcon mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.size.mas_equalTo(CGSizeMake(21, 21));
|
||
}];
|
||
|
||
[self.winPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.height.mas_equalTo(35);
|
||
}];
|
||
|
||
UIStackView *stackView_2 = [[UIStackView alloc] init];
|
||
stackView_2.spacing = 4;
|
||
[self addSubview:stackView_2];
|
||
[stackView_2 mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.centerX.mas_equalTo(self.backgroundImageView);
|
||
make.top.mas_equalTo(stackView.mas_bottom).offset(11);
|
||
make.height.mas_equalTo(17);
|
||
}];
|
||
|
||
UILabel *titleLeft = [UILabel labelInitWithText:YMLocalizedString(@"Combo_4") font:kFontRegular(12) textColor:[UIColor whiteColor]];
|
||
UILabel *titleRight = [UILabel labelInitWithText:YMLocalizedString(@"Combo_9") font:kFontRegular(12) textColor:[UIColor whiteColor]];
|
||
|
||
[stackView_2 addArrangedSubview:titleLeft];
|
||
[stackView_2 addArrangedSubview:self.winTimesLabel];
|
||
[stackView_2 addArrangedSubview:titleRight];
|
||
}
|
||
|
||
- (void)setModel:(LuckyGiftWinningFlagViewModel *)model {
|
||
_model = model;
|
||
self.winPriceLabel.text = model.coins;
|
||
self.winTimesLabel.text = model.times;
|
||
self.backgroundImageView.image = model.level == 1 ? kImage(@"luck_gift_gold") : kImage(@"luck_gift_pruple");
|
||
}
|
||
|
||
- (void)display {
|
||
|
||
}
|
||
|
||
#pragma mark -
|
||
- (UIImageView *)coinIcon {
|
||
if (!_coinIcon) {
|
||
_coinIcon = [[UIImageView alloc] initWithImage:kImage(@"moli_money_icon")];
|
||
_coinIcon.contentMode = UIViewContentModeScaleAspectFit;
|
||
}
|
||
return _coinIcon;
|
||
}
|
||
|
||
- (UIImageView *)backgroundImageView {
|
||
if (!_backgroundImageView) {
|
||
_backgroundImageView = [[UIImageView alloc] initWithImage:kImage(@"luck_gift_gold")];
|
||
_backgroundImageView.contentMode = UIViewContentModeScaleAspectFit;
|
||
}
|
||
return _backgroundImageView;
|
||
}
|
||
|
||
- (UILabel *)winLabel {
|
||
if (!_winLabel) {
|
||
_winLabel = [UILabel labelInitWithText:YMLocalizedString(@"Combo_4") font:kFontSemibold(14) textColor:UIColorFromRGB(0xffe375)];
|
||
_winLabel.textAlignment = NSTextAlignmentCenter;
|
||
}
|
||
return _winLabel;
|
||
}
|
||
|
||
- (UILabel *)winPriceLabel {
|
||
if (!_winPriceLabel) {
|
||
_winPriceLabel = [UILabel labelInitWithText:@"" font:kFontSemibold(26) textColor:UIColorFromRGB(0xffe375)];
|
||
_winPriceLabel.minimumScaleFactor = 0.5f;
|
||
}
|
||
return _winPriceLabel;
|
||
}
|
||
|
||
- (UILabel *)winTimesLabel {
|
||
if (!_winTimesLabel) {
|
||
_winTimesLabel = [UILabel labelInitWithText:@"" font:kFontSemibold(14) textColor:UIColorFromRGB(0xffe375)];
|
||
}
|
||
return _winTimesLabel;
|
||
}
|
||
|
||
|
||
|
||
@end
|