Files
featherVoice/QXLive/Tabbar/弹窗/QXGiftDriftView.m
2025-08-08 10:49:36 +08:00

117 lines
4.2 KiB
Objective-C

//
// QXGiftDriftView.m
// QXLive
//
// Created by 启星 on 2025/5/21.
//
#import "QXGiftDriftView.h"
@interface QXGiftDriftView()
@property (nonatomic,strong)UIImageView *bgImageView;
@property (nonatomic,strong)UILabel *titleLabel;
@property (nonatomic,strong)UIImageView *giftImageView;
@property (nonatomic,strong)UILabel *countLabel;
@property (nonatomic,assign)BOOL isPlaying;
@end
@implementation QXGiftDriftView
+(instancetype)shareView{
static QXGiftDriftView *manager = nil;
static dispatch_once_t predicate;
dispatch_once(&predicate, ^{
manager = [[QXGiftDriftView alloc] init];
});
return manager;
}
- (instancetype)init
{
self = [super init];
if (self) {
self.frame = CGRectMake(SCREEN_WIDTH, 150, ScaleWidth(316), ScaleWidth(50));
[self initSubviews];
}
return self;
}
-(void)initSubviews{
self.bgImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"pop_gift_bg"]];
self.bgImageView.frame = self.bounds;
[self addSubview:self.bgImageView];
self.titleLabel = [[UILabel alloc] init];
self.titleLabel.font = [UIFont systemFontOfSize:14];
self.titleLabel.textColor = UIColor.whiteColor;
[self addSubview:self.titleLabel];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self).offset(-ScaleWidth(30));
make.height.mas_equalTo(30);
make.centerY.equalTo(self).offset(2);
}];
self.giftImageView = [[UIImageView alloc] init];
self.giftImageView.contentMode = UIViewContentModeScaleAspectFit;
[self addSubview:self.giftImageView];
[self.giftImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.titleLabel.mas_right).offset(5);
make.height.width.mas_equalTo(20);
make.centerY.equalTo(self).offset(2);
}];
self.countLabel = [[UILabel alloc] init];
self.countLabel.font = [UIFont systemFontOfSize:14];
self.countLabel.textColor = UIColor.whiteColor;
[self addSubview:self.countLabel];
[self.countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.giftImageView.mas_right);
make.height.mas_equalTo(30);
make.centerY.equalTo(self).offset(2);
}];
}
-(void)addGiftModel:(QXGiftScrollModel *)model{
[self.dataArray addObject:model];
[self giftAction];
}
-(void)giftAction{
if (self.isPlaying) {
return;
}
[QXGiftDriftView shareView].isPlaying = YES;
[QXGiftDriftView shareView].model = [QXGiftDriftView shareView].dataArray.firstObject;
[KEYWINDOW addSubview:[QXGiftDriftView shareView]];
[UIView animateWithDuration:1.5 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
[QXGiftDriftView shareView].x = (SCREEN_WIDTH-ScaleWidth(316))/2;
} completion:^(BOOL finished) {
[UIView animateWithDuration:2 delay:1 options:UIViewAnimationOptionCurveEaseIn animations:^{
[QXGiftDriftView shareView].x = -SCREEN_WIDTH;
} completion:^(BOOL finished) {
[QXGiftDriftView shareView].x = SCREEN_WIDTH;
[[QXGiftDriftView shareView] removeFromSuperview];
[[QXGiftDriftView shareView].dataArray removeFirstObject];
[QXGiftDriftView shareView].isPlaying = NO;
if ([QXGiftDriftView shareView].dataArray.count>0) {
[[QXGiftDriftView shareView] giftAction];
}
}];
}];
}
-(void)setModel:(QXGiftScrollModel *)model{
_model = model;
NSString *str = [NSString stringWithFormat:@"%@送给%@",model.fromUserName,model.toUserName];
NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:str];
[attr yy_setColor:RGB16(0xFFDE77) range:[str rangeOfString:model.fromUserName]];
[attr yy_setColor:RGB16(0xFFDE77) range:[str rangeOfString:model.toUserName]];
self.titleLabel.attributedText = attr;
[self.giftImageView sd_setImageWithURL:[NSURL URLWithString:model.gift_picture]];
self.countLabel.text = [NSString stringWithFormat:@"X%@",model.number];
}
-(NSMutableArray *)dataArray{
if (!_dataArray) {
_dataArray = [NSMutableArray array];
}
return _dataArray;
}
@end