230 lines
9.2 KiB
Objective-C
230 lines
9.2 KiB
Objective-C
//
|
|
// QXRoomBarSetGiftView.m
|
|
// QXLive
|
|
//
|
|
// Created by 启星 on 2026/1/4.
|
|
//
|
|
|
|
#import "QXRoomBarSetGiftView.h"
|
|
#import "QXRoomBarSetGiftCell.h"
|
|
#import "QXMineNetwork.h"
|
|
#import "QXRoomBarSetShowTimeView.h"
|
|
|
|
@interface QXRoomBarSetGiftView()<UIGestureRecognizerDelegate,UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout,QXRoomBarSetGiftCellDelegate>
|
|
@property (nonatomic,strong)UIView *bgView;
|
|
@property (nonatomic,strong)UILabel *titleLabel;
|
|
@property (nonatomic,strong)UILabel *subTitleLabel;
|
|
@property (nonatomic,strong)UICollectionView *collectionView;
|
|
@property (nonatomic,strong)QXGiftModel *selectedModel;
|
|
@property (nonatomic,strong)NSMutableArray *dataArray;
|
|
|
|
@property (nonatomic,strong)UIButton *cancelBtn;
|
|
@property (nonatomic,strong)UIButton *commitBtn;
|
|
@end
|
|
|
|
@implementation QXRoomBarSetGiftView
|
|
- (instancetype)init
|
|
{
|
|
self = [super init];
|
|
if (self) {
|
|
self.frame = UIScreen.mainScreen.bounds;
|
|
[self initSubviews];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
-(void)initSubviews{
|
|
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hide)];
|
|
self.backgroundColor = RGB16A(0x000000, 0.3);
|
|
tap.delegate = self;
|
|
[self addGestureRecognizer:tap];
|
|
|
|
self.bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, ScaleWidth(429)+kSafeAreaBottom)];
|
|
self.bgView.backgroundColor = RGB16(0x103E30);
|
|
[self.bgView addRoundedCornersWithRadius:14 byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight)];
|
|
[self addSubview:self.bgView];
|
|
|
|
// self.bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.bgView.width, self.bgView.height)];
|
|
// self.bgImageView.image = [UIImage imageNamed:@"room_sound_bg"];
|
|
// [self.bgView addSubview:self.bgImageView];
|
|
|
|
|
|
self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(16, 16, self.bgView.width-32, 24)];
|
|
self.titleLabel.font = [UIFont boldSystemFontOfSize:18];
|
|
self.titleLabel.textColor = RGB16(0xffffff);
|
|
self.titleLabel.textAlignment = NSTextAlignmentCenter;
|
|
self.titleLabel.text = @"设置你的自定义礼物";
|
|
[self.bgView addSubview:self.titleLabel];
|
|
|
|
self.subTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(16, self.titleLabel.bottom+10, self.bgView.width-32, 24)];
|
|
self.subTitleLabel.font = [UIFont systemFontOfSize:13];
|
|
self.subTitleLabel.textColor = RGB16(0x999999);
|
|
self.subTitleLabel.textAlignment = NSTextAlignmentLeft;
|
|
self.subTitleLabel.text = @"设置每个礼物对应的表演内容,上麦位后其他人可见";
|
|
[self.bgView addSubview:self.subTitleLabel];
|
|
|
|
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
|
|
layout.minimumLineSpacing = 12;
|
|
layout.minimumInteritemSpacing = 12;
|
|
layout.sectionInset = UIEdgeInsetsMake(0, 16, 0, 16);
|
|
layout.scrollDirection = UICollectionViewScrollDirectionVertical;
|
|
self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, self.subTitleLabel.bottom+10, self.bgView.width, self.bgView.height-self.subTitleLabel.bottom-20) collectionViewLayout:layout];
|
|
[self.collectionView registerNib:[UINib nibWithNibName:@"QXRoomBarSetGiftCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"QXRoomBarSetGiftCell"];
|
|
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.cancelBtn = [[UIButton alloc] init];
|
|
[self.cancelBtn setTitle:@"取消" forState:(UIControlStateNormal)];
|
|
[self.cancelBtn setTitleColor:RGB16(0x999999) forState:(UIControlStateNormal)];
|
|
[self.cancelBtn addTarget:self action:@selector(cancelAction) forControlEvents:(UIControlEventTouchUpInside)];
|
|
self.cancelBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
|
|
self.cancelBtn.titleLabel.font = [UIFont systemFontOfSize:15];
|
|
[self.bgView addSubview:self.cancelBtn];
|
|
[self.cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.mas_equalTo(16);
|
|
make.height.mas_equalTo(30);
|
|
make.width.mas_equalTo(50);
|
|
make.centerY.equalTo(self.titleLabel);
|
|
}];
|
|
|
|
self.commitBtn = [[UIButton alloc] init];
|
|
[self.commitBtn setTitle:@"确定" forState:(UIControlStateNormal)];
|
|
[self.commitBtn setTitleColor:QXConfig.themeColor forState:(UIControlStateNormal)];
|
|
[self.commitBtn addTarget:self action:@selector(commitAction) forControlEvents:(UIControlEventTouchUpInside)];
|
|
self.commitBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
|
|
self.commitBtn.titleLabel.font = [UIFont systemFontOfSize:15];
|
|
[self.bgView addSubview:self.commitBtn];
|
|
[self.commitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.right.mas_equalTo(-16);
|
|
make.height.mas_equalTo(30);
|
|
make.width.mas_equalTo(50);
|
|
make.centerY.equalTo(self.titleLabel);
|
|
}];
|
|
}
|
|
-(void)setIsLikeGift:(BOOL)isLikeGift{
|
|
_isLikeGift = isLikeGift;
|
|
self.cancelBtn.hidden = !isLikeGift;
|
|
self.commitBtn.hidden = !isLikeGift;
|
|
self.titleLabel.text = isLikeGift?@"选择你的心愿礼物":@"设置你的自定义礼物";
|
|
self.subTitleLabel.text = isLikeGift?@"其他人赠送你心愿礼物,则能邀请你进入私密房间":@"设置每个礼物对应的表演内容,上麦位后其他人可见";
|
|
}
|
|
|
|
-(void)setPitNumber:(NSString *)pitNumber{
|
|
_pitNumber = pitNumber;
|
|
}
|
|
-(void)cancelAction{
|
|
[self hide];
|
|
}
|
|
|
|
-(void)commitAction{
|
|
if (!self.selectedModel) {
|
|
showToast(@"请选择礼物");
|
|
return;
|
|
}
|
|
if (self.delegate && [self.delegate respondsToSelector:@selector(setGiftModelIsLikeGift:giftModel:pitNumber:setGiftView:)]) {
|
|
[self.delegate setGiftModelIsLikeGift:self.isLikeGift giftModel:self.selectedModel pitNumber:self.pitNumber setGiftView:self];
|
|
}
|
|
}
|
|
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
|
|
return touch.view == self;
|
|
}
|
|
-(void)getGiftList{
|
|
MJWeakSelf
|
|
[QXMineNetwork getRoomNewGiftListWithLabel:self.isLikeGift?@"15":@"14" type:@"6" successBlock:^(NSArray<QXGiftModel *> * _Nonnull list) {
|
|
[weakSelf.dataArray removeAllObjects];
|
|
[weakSelf.dataArray addObjectsFromArray:list];
|
|
[weakSelf.collectionView reloadData];
|
|
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
|
|
|
|
}];
|
|
}
|
|
|
|
-(void)setShowTimeGiftModel:(QXGiftModel *)giftModel{
|
|
QXRoomBarSetShowTimeView *view = [[QXRoomBarSetShowTimeView alloc] init];
|
|
view.roomId = self.roomId;
|
|
view.giftModel = giftModel;
|
|
MJWeakSelf
|
|
view.commitBlock = ^{
|
|
[weakSelf getGiftList];
|
|
};
|
|
[view showInView:self.superview];
|
|
}
|
|
|
|
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
|
|
return self.dataArray.count;
|
|
}
|
|
|
|
-(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
|
|
QXRoomBarSetGiftCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QXRoomBarSetGiftCell" forIndexPath:indexPath];
|
|
cell.cellType = self.isLikeGift?QXRoomBarSetGiftCellTypeNoOption:QXRoomBarSetGiftCellTypeSet;
|
|
cell.model = self.dataArray[indexPath.row];
|
|
cell.delegate = self;
|
|
return cell;
|
|
}
|
|
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
|
|
CGFloat itemWidth = (SCREEN_WIDTH-16*2-12*3)/4;
|
|
if (self.isLikeGift) {
|
|
return CGSizeMake(itemWidth, itemWidth+50);
|
|
}else{
|
|
return CGSizeMake(itemWidth, itemWidth+82+30);
|
|
}
|
|
}
|
|
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
|
|
if (!self.isLikeGift) {
|
|
return;
|
|
}
|
|
|
|
QXGiftModel *model = self.dataArray[indexPath.row];
|
|
if (model.isSelected) {
|
|
return;
|
|
}
|
|
if (self.selectedModel) {
|
|
self.selectedModel.isSelected = NO;
|
|
}
|
|
model.isSelected = YES;
|
|
self.selectedModel = model;
|
|
[collectionView reloadData];
|
|
}
|
|
-(NSMutableArray *)dataArray{
|
|
if (!_dataArray) {
|
|
_dataArray = [NSMutableArray array];
|
|
}
|
|
return _dataArray;
|
|
}
|
|
|
|
-(void)showInView:(UIView *)view{
|
|
self.selectedModel = nil;
|
|
[self.collectionView reloadData];
|
|
[self getGiftList];
|
|
self.bgView.y = SCREEN_HEIGHT;
|
|
[view addSubview:self];
|
|
[UIView animateWithDuration:0.3 animations:^{
|
|
self.bgView.y = SCREEN_HEIGHT-ScaleWidth(429)-kSafeAreaBottom;
|
|
}];
|
|
}
|
|
-(void)hide{
|
|
if (!self.superview) {
|
|
NSLog(@"⚠️ View already removed from superview");
|
|
return;
|
|
}
|
|
[UIView animateWithDuration:0.3 animations:^{
|
|
if (self.bgView) {
|
|
self.bgView.y = SCREEN_HEIGHT;
|
|
}
|
|
} completion:^(BOOL finished) {
|
|
// 检查是否已经被移除
|
|
if (self.superview) {
|
|
[self removeFromSuperview];
|
|
}
|
|
// 避免在 dealloc 过程中访问其他属性
|
|
// 不要在 completion block 中访问或设置其他属性
|
|
}];
|
|
}
|
|
@end
|