2025-08-08 10:49:36 +08:00
|
|
|
//
|
|
|
|
|
// QXSetApplyGiftView.m
|
|
|
|
|
// QXLive
|
|
|
|
|
//
|
|
|
|
|
// Created by 启星 on 2025/6/16.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#import "QXSetApplyGiftView.h"
|
|
|
|
|
#import "QXMineNetwork.h"
|
|
|
|
|
#import "QXGiftCell.h"
|
|
|
|
|
|
|
|
|
|
@interface QXSetApplyGiftView()<UICollectionViewDelegate,UICollectionViewDataSource,UIGestureRecognizerDelegate>
|
|
|
|
|
@property (nonatomic,strong)UIView *bgView;
|
|
|
|
|
@property (nonatomic,strong)UIImageView *bgImageView;
|
|
|
|
|
@property (nonatomic,strong)UICollectionView *collectionView;
|
|
|
|
|
@property (nonatomic,assign)NSInteger selectedIndex;
|
|
|
|
|
@property (nonatomic,strong)NSMutableArray *dataArray;
|
|
|
|
|
@property (nonatomic,strong)UILabel *titleLabel;
|
|
|
|
|
|
|
|
|
|
@property (nonatomic,strong)UIButton *cancelBtn;
|
|
|
|
|
@property (nonatomic,strong)UIButton *commitBtn;
|
|
|
|
|
@end
|
|
|
|
|
@implementation QXSetApplyGiftView
|
|
|
|
|
|
|
|
|
|
- (instancetype)initWithFrame:(CGRect)frame
|
|
|
|
|
{
|
|
|
|
|
self = [super initWithFrame:frame];
|
|
|
|
|
if (self) {
|
|
|
|
|
[self initSubviews];
|
|
|
|
|
}
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-(void)initSubviews{
|
|
|
|
|
self.selectedIndex = -1;
|
|
|
|
|
self.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.3];
|
|
|
|
|
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hide)];
|
|
|
|
|
tap.delegate = self;
|
|
|
|
|
[self addGestureRecognizer:tap];
|
|
|
|
|
self.bgView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, ScaleWidth(456)+kSafeAreaBottom)];
|
|
|
|
|
[self addSubview:self.bgView];
|
|
|
|
|
|
|
|
|
|
self.bgImageView = [[UIImageView alloc] initWithFrame:self.bgView.bounds];
|
|
|
|
|
self.bgImageView.image = [UIImage imageNamed:@"room_sound_bg"];
|
|
|
|
|
[self.bgView addSubview:self.bgImageView];
|
|
|
|
|
|
|
|
|
|
self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(16, 16, 150, 24)];
|
|
|
|
|
self.titleLabel.textColor = UIColor.whiteColor;
|
|
|
|
|
self.titleLabel.font = [UIFont boldSystemFontOfSize:16];
|
|
|
|
|
self.titleLabel.text = QXText(@"设置插队礼物");
|
|
|
|
|
[self.bgView addSubview:self.titleLabel];
|
|
|
|
|
|
|
|
|
|
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
|
|
|
|
|
layout.itemSize = CGSizeMake((SCREEN_WIDTH-16*2-12*3)/4, ScaleWidth(119));
|
|
|
|
|
layout.minimumLineSpacing = 12;
|
|
|
|
|
layout.minimumInteritemSpacing = 12;
|
|
|
|
|
layout.sectionInset = UIEdgeInsetsMake(0, 16, 0, 16);
|
|
|
|
|
layout.scrollDirection = UICollectionViewScrollDirectionVertical;
|
|
|
|
|
self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, self.titleLabel.bottom+12, self.width, self.bgView.height-kSafeAreaBottom-42-self.titleLabel.bottom-12-10) collectionViewLayout:layout];
|
|
|
|
|
[self.collectionView registerNib:[UINib nibWithNibName:@"QXGiftCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"QXGiftCell"];
|
|
|
|
|
self.collectionView.delegate = self;
|
|
|
|
|
self.collectionView.dataSource = self;
|
|
|
|
|
self.collectionView.showsHorizontalScrollIndicator = NO;
|
|
|
|
|
self.collectionView.bounces = NO;
|
|
|
|
|
self.collectionView.backgroundColor = [UIColor clearColor];
|
|
|
|
|
[self.bgView addSubview:self.collectionView];
|
|
|
|
|
|
|
|
|
|
self.cancelBtn = [[UIButton alloc] initWithFrame:CGRectMake(38, self.bgView.height-kSafeAreaBottom-42, 95, 42)];
|
|
|
|
|
[self.cancelBtn setTitle:QXText(@"取消") forState:(UIControlStateNormal)];
|
|
|
|
|
[self.cancelBtn setTitleColor:UIColor.whiteColor forState:(UIControlStateNormal)];
|
|
|
|
|
[self.cancelBtn addTarget:self action:@selector(hide) forControlEvents:(UIControlEventTouchUpInside)];
|
|
|
|
|
[self.cancelBtn addRoundedCornersWithRadius:21];
|
|
|
|
|
self.cancelBtn.titleLabel.font = [UIFont systemFontOfSize:14];
|
|
|
|
|
self.cancelBtn.backgroundColor = RGB16(0x333333);
|
|
|
|
|
|
|
|
|
|
[self.bgView addSubview:self.cancelBtn];
|
|
|
|
|
|
|
|
|
|
self.commitBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.cancelBtn.right+16, self.bgView.height-kSafeAreaBottom-42, self.bgView.width-38-self.cancelBtn.right-16 , 42)];
|
|
|
|
|
[self.commitBtn setTitle:QXText(@"确定") forState:(UIControlStateNormal)];
|
|
|
|
|
[self.commitBtn setTitleColor:QXConfig.btnTextColor forState:(UIControlStateNormal)];
|
|
|
|
|
[self.commitBtn addTarget:self action:@selector(commitAction) forControlEvents:(UIControlEventTouchUpInside)];
|
|
|
|
|
[self.commitBtn addRoundedCornersWithRadius:21];
|
|
|
|
|
self.commitBtn.titleLabel.font = [UIFont systemFontOfSize:14];
|
|
|
|
|
self.commitBtn.backgroundColor = QXConfig.themeColor;
|
|
|
|
|
|
|
|
|
|
[self.bgView addSubview:self.commitBtn];
|
|
|
|
|
[self getGiftList];
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
|
|
|
|
|
return touch.view == self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-(void)getGiftList{
|
|
|
|
|
MJWeakSelf
|
2025-10-20 09:43:10 +08:00
|
|
|
[QXMineNetwork giftListWithLabel:@"0" roomId:self.roomId successBlock:^(NSArray<QXGiftModel *> * _Nonnull list) {
|
2025-08-08 10:49:36 +08:00
|
|
|
weakSelf.selectedIndex = -1;
|
|
|
|
|
[weakSelf.dataArray removeAllObjects];
|
|
|
|
|
[weakSelf.dataArray addObjectsFromArray:list];
|
|
|
|
|
[weakSelf.collectionView reloadData];
|
|
|
|
|
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
|
|
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-(void)commitAction{
|
|
|
|
|
if (self.selectedIndex == -1) {
|
|
|
|
|
showToast(@"请选择礼物");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
QXGiftModel *model = self.dataArray[self.selectedIndex];
|
|
|
|
|
MJWeakSelf
|
|
|
|
|
[QXMineNetwork setApplyPitGiftWithRoomId:self.roomId gift_id:model.gift_id successBlock:^(NSDictionary * _Nonnull dict) {
|
|
|
|
|
if (weakSelf.setScuseesBlock) {
|
|
|
|
|
weakSelf.setScuseesBlock();
|
|
|
|
|
}
|
|
|
|
|
[weakSelf hide];
|
|
|
|
|
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
|
|
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
|
|
|
|
|
return self.dataArray.count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
|
|
|
|
|
QXGiftCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QXGiftCell" forIndexPath:indexPath];
|
|
|
|
|
cell.cellType = QXGiftCellTypeLive;
|
|
|
|
|
cell.roomGiftModel = self.dataArray[indexPath.row];
|
|
|
|
|
if (self.selectedIndex == indexPath.row) {
|
|
|
|
|
cell.selecteBtn.selected = YES;
|
|
|
|
|
}else{
|
|
|
|
|
cell.selecteBtn.selected = NO;
|
|
|
|
|
}
|
|
|
|
|
return cell;
|
|
|
|
|
}
|
|
|
|
|
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
|
|
|
|
|
if (indexPath.row == self.selectedIndex) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
self.selectedIndex = indexPath.row;
|
|
|
|
|
[collectionView reloadData];
|
|
|
|
|
}
|
|
|
|
|
-(void)showInView:(UIView *)view{
|
|
|
|
|
[view addSubview:self];
|
|
|
|
|
[UIView animateWithDuration:0.3 animations:^{
|
|
|
|
|
self.bgView.y = SCREEN_HEIGHT-ScaleWidth(456)-kSafeAreaBottom;
|
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
-(void)hide{
|
|
|
|
|
[UIView animateWithDuration:0.3 animations:^{
|
|
|
|
|
self.bgView.y = SCREEN_HEIGHT;
|
|
|
|
|
} completion:^(BOOL finished) {
|
|
|
|
|
[self removeFromSuperview];
|
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
-(NSMutableArray *)dataArray{
|
|
|
|
|
if (!_dataArray) {
|
|
|
|
|
_dataArray = [NSMutableArray array] ;
|
|
|
|
|
}
|
|
|
|
|
return _dataArray;
|
|
|
|
|
}
|
|
|
|
|
@end
|