Files
featherVoice/QXLive/Room(房间)/View/红包/QXRedBagListView.m
2025-10-20 10:29:42 +08:00

229 lines
8.9 KiB
Objective-C

//
// QXRedBagListView.m
// QXLive
//
// Created by 启星 on 2025/10/11.
//
#import "QXRedBagListView.h"
@interface QXRedBagListView()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (nonatomic,strong)UIView *bigBgView;
@property (nonatomic,strong)UIImageView *bigBgImageView;
@property (nonatomic,strong)UIView *bgView;
@property (nonatomic,strong)UIImageView *bgImageView;
@property (nonatomic,strong)UIImageView *bottomImageView;
@property (nonatomic,strong)UIButton *closeBtn;
@property (nonatomic,strong)UICollectionView *collectionView;
@end
@implementation QXRedBagListView
- (instancetype)init
{
self = [super init];
if (self) {
self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
[self initSubviews];
}
return self;
}
-(void)initSubviews{
self.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.3];
self.bigBgView = [[UIView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-375)/2, (SCREEN_HEIGHT-480)/2, 375, 480)];
[self addSubview:self.bigBgView];
self.bigBgImageView = [[UIImageView alloc] initWithFrame:self.bigBgView.bounds];
self.bigBgImageView.image = [UIImage imageNamed:@"red_bag_list_big_bg"];
[self.bigBgView addSubview:self.bigBgImageView];
self.bgView = [[UIView alloc] init];
[self.bgView addRoundedCornersWithRadius:10];
[self.bigBgView addSubview:self.bgView];
[self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(280);
make.height.mas_equalTo(272);
make.centerX.equalTo(self.bigBgView);
make.top.mas_equalTo(60);
}];
self.bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.bgView.width, 242)];
self.bgImageView.image = [UIImage imageNamed:@"red_bag_list_bg"];
[self.bgView addSubview:self.bgImageView];
[self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.top.equalTo(self.bgView);
make.height.mas_equalTo(242);
}];
self.bottomImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"red_bag_list_bottom_bg"]];
self.bottomImageView.contentMode = UIViewContentModeScaleToFill;
[self.bgView addSubview:self.bottomImageView];
[self.bottomImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.bottom.right.equalTo(self.bgView);
make.top.equalTo(self.bgImageView.mas_bottom).offset(-1);
}];
self.closeBtn = [[UIButton alloc] init];
[self.closeBtn setBackgroundImage:[UIImage imageNamed:@"home_white_close"] forState:(UIControlStateNormal)];
[self.closeBtn addTarget:self action:@selector(closeAction) forControlEvents:(UIControlEventTouchUpInside)];
[self.bigBgView addSubview:self.closeBtn];
[self.closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self);
make.top.equalTo(self.bgView.mas_bottom).offset(40);
make.height.width.mas_equalTo(30);
}];
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.itemSize = CGSizeMake(66,86);
layout.minimumLineSpacing =20;
layout.minimumInteritemSpacing =16;
layout.scrollDirection = UICollectionViewScrollDirectionVertical;
self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
[self.collectionView registerClass:[QXRedBagListCell class] forCellWithReuseIdentifier:@"QXRedBagListCell"];
self.collectionView.delegate = self;
self.collectionView.dataSource = self;
self.collectionView.showsHorizontalScrollIndicator = NO;
self.collectionView.showsVerticalScrollIndicator = NO;
self.collectionView.bounces = NO;
self.collectionView.backgroundColor = [UIColor clearColor];
[self.bgView addSubview:self.collectionView];
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(25);
make.right.mas_equalTo(-25);
make.bottom.mas_equalTo(-30);
make.top.mas_equalTo(156);
}];
}
-(void)updateRedpacketTimeWithIndex:(NSInteger)index time:(long)time{
QXRedBagListCell *cell = [self.collectionView cellForItemAtIndexPath:[NSIndexPath indexPathForRow:index inSection:0]];
cell.endTime = time;
}
-(void)setDataArray:(NSArray<QXRedPacketModel *> *)dataArray{
_dataArray = dataArray;
if (dataArray.count >3) {
[self.bgView mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(358);
}];
}else{
[self.bgView mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(272);
}];
}
[self.collectionView reloadData];
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return self.dataArray.count;
}
-(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
QXRedBagListCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QXRedBagListCell" forIndexPath:indexPath];
cell.redpacketModel = self.dataArray[indexPath.row];
return cell;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
QXRedPacketModel *model = self.dataArray[indexPath.row];
if (self.didSelectedRedBlock) {
self.didSelectedRedBlock(model);
}
[self hide];
}
-(void)closeAction{
[self hide];
}
-(void)showInView:(UIView *)view{
self.bigBgView.y = -SCREEN_HEIGHT;
[view addSubview:self];
[UIView animateWithDuration:0.3 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:1.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
self.bigBgView.y = (SCREEN_HEIGHT-480)/2;
} completion:^(BOOL finished) {
}];
}
-(void)hide{
[UIView animateWithDuration:0.3 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:1.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
self.bigBgView.y = SCREEN_HEIGHT;
} completion:^(BOOL finished) {
[self removeFromSuperview];
}];
}
@end
@implementation QXRedBagListCell
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.contentView.backgroundColor = [UIColor clearColor];
[self initSubviews];
}
return self;
}
-(void)setRedpacketModel:(QXRedPacketModel *)redpacketModel{
_redpacketModel = redpacketModel;
self.redBagImageView.image = [UIImage imageNamed:redpacketModel.is_qiang.intValue==1?@"red_bag_list_is_get_icon":@"red_bag_list_icon"];
self.pwdImageView.hidden = redpacketModel.type.intValue!=2;
self.nameLabel.text = redpacketModel.nickname;
if (self.redpacketModel.countdown.intValue==0) {
self.timeLabel.hidden = YES;
}
}
-(void)setEndTime:(long)endTime{
if (self.redpacketModel.countdown.intValue==0) {
self.timeLabel.hidden = YES;
return;
}
if (endTime<=0) {
self.timeLabel.hidden = YES;
return;
}
self.timeLabel.hidden = NO;
NSInteger min = (endTime % 3600) / 60;
NSInteger second = endTime % 60;
self.timeLabel.text = [NSString stringWithFormat:@" %02ld:%02ld ",min,second];
}
-(void)initSubviews{
self.redBagImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"red_bag_list_icon"]];
[self.contentView addSubview:self.redBagImageView];
[self.redBagImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(4);
make.height.mas_equalTo(66);
make.width.mas_equalTo(66);
make.centerX.equalTo(self.contentView);
}];
self.pwdImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"red_bag_list_pwd_icon"]];
[self.contentView addSubview:self.pwdImageView];
[self.pwdImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.top.equalTo(self.contentView);
make.width.mas_equalTo(34);
make.height.mas_equalTo(18);
}];
self.timeLabel = [[UILabel alloc] init];
self.timeLabel.textColor = RGB16(0xffffff);
[self.timeLabel addRoundedCornersWithRadius:6];
self.timeLabel.hidden = YES;
self.timeLabel.backgroundColor = RGB16A(0x000000, 0.25);
self.timeLabel.font = [UIFont systemFontOfSize:12];
[self.contentView addSubview:self.timeLabel];
[self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(self.redBagImageView);
make.centerX.equalTo(self.contentView);
make.height.mas_equalTo(12);
}];
self.nameLabel = [[UILabel alloc] init];
self.nameLabel.textColor = RGB16(0xD04248);
self.nameLabel.font = [UIFont systemFontOfSize:12];
[self.contentView addSubview:self.nameLabel];
[self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(self.contentView);
make.centerX.equalTo(self.contentView);
make.height.mas_equalTo(12);
}];
}
@end