Files
featherVoice/QXLive/Room(房间)/View/酒吧房/QXRoomBarSendCustomGiftView.m
2026-01-08 18:31:27 +08:00

179 lines
7.4 KiB
Objective-C

//
// QXRoomBarSendCustomGiftView.m
// QXLive
//
// Created by 启星 on 2026/1/5.
//
#import "QXRoomBarSendCustomGiftView.h"
#import "QXRoomBarSetGiftCell.h"
#import "QXMineNetwork.h"
@interface QXRoomBarSendCustomGiftView ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout,QXRoomBarSetGiftCellDelegate>
@property (nonatomic,strong)UIView *bgView;
@property (nonatomic,strong)UIImageView *bgImageView;
@property (nonatomic,strong)UILabel *titleLabel;
@property (nonatomic,strong)UIImageView *headerImageView;
@property (nonatomic,strong)UILabel *nameLabel;
@property (nonatomic,strong)UIButton *closeBtn;
@property (nonatomic,strong)UICollectionView *collectionView;
@property (nonatomic,strong)NSMutableArray *dataArray;
@end
@implementation QXRoomBarSendCustomGiftView
- (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((self.width-ScaleWidth(287))/2, 0, ScaleWidth(287), ScaleWidth(300))];
self.bgView.backgroundColor = RGB16(0xffffff);
[self.bgView addRoundedCornersWithRadius:16];
[self addSubview:self.bgView];
self.bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.bgView.width, self.bgView.height)];
self.bgImageView.backgroundColor = RGB16(0x9722D6);
[self.bgView addSubview:self.bgImageView];
self.titleLabel = [[UILabel alloc] init];
self.titleLabel.font = [UIFont boldSystemFontOfSize:13];
self.titleLabel.textColor = RGB16A(0xFFFFFF,0.65);
self.titleLabel.text = @"送给";
[self.bgView addSubview:self.titleLabel];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(16);
make.height.mas_equalTo(17);
make.top.mas_equalTo(ScaleWidth(19));
}];
self.headerImageView = [[UIImageView alloc] init];
[self.bgView addSubview:self.headerImageView];
[self.headerImageView addRoundedCornersWithRadius:ScaleWidth(16)];
self.headerImageView.contentMode = UIViewContentModeScaleAspectFill;
[self.headerImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.titleLabel.mas_right).offset(2);
make.height.width.mas_equalTo(ScaleWidth(32));
make.centerY.equalTo(self.titleLabel);
}];
self.nameLabel = [[UILabel alloc] init];
self.nameLabel.font = [UIFont boldSystemFontOfSize:13];
self.nameLabel.textColor = RGB16(0xFFFFFF);
self.nameLabel.text = @"羽声语音";
[self.bgView addSubview:self.nameLabel];
[self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.headerImageView.mas_right).offset(2);
make.height.mas_equalTo(17);
make.centerY.equalTo(self.titleLabel);
}];
self.closeBtn = [[UIButton alloc] init];
[self.closeBtn setImage:[[UIImage imageNamed:@"wallet_close"] imageByTintColor:RGB16(0xffffff)] forState:(UIControlStateNormal)];
[self.closeBtn addTarget:self action:@selector(hide) forControlEvents:(UIControlEventTouchUpInside)];
[self.bgView addSubview:self.closeBtn];
[self.closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.mas_equalTo(30);
make.right.mas_equalTo(-5);
make.centerY.equalTo(self.titleLabel);
}];
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:CGRectZero 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.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self.bgView);
make.top.equalTo(self.headerImageView.mas_bottom).offset(10);
make.bottom.mas_equalTo(-15);
}];
}
-(void)setPitModel:(QXRoomPitModel *)pitModel{
_pitModel = pitModel;
[self.headerImageView sd_setImageWithURL:[NSURL URLWithString:pitModel.avatar]];
self.nameLabel.text = pitModel.nickname;
}
-(void)getGiftList{
MJWeakSelf
[QXMineNetwork getRoomCustomGiftWithUserId:self.pitModel.user_id 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{
QXLOG(@"送自定义礼物%@",giftModel.gift_name);
[QXMineNetwork roomSendGiftWithRoomId:self.roomId gift_id:giftModel.gift_id gift_num:@"1" to_uid:self.pitModel.user_id heart_id:@"" type:@"1" pit_number:@"" gift_bag_id:giftModel.gift_bag successBlock:^(NSDictionary * _Nonnull dict) {
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
showToast(msg);
}];
}
-(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 = QXRoomBarSetGiftCellTypeSend;
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;
return CGSizeMake(itemWidth, itemWidth+82+30);
}
-(void)showInView:(UIView *)view{
[self getGiftList];
self.bgView.y = -view.height;
[view addSubview:self];
[UIView animateWithDuration:0.3 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:1.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
self.bgView.y = (view.height-self.bgView.height)/2.0;
} completion:^(BOOL finished) {
}];
}
-(void)hide{
[UIView animateWithDuration:0.3 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:1.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
self.bgView.y = SCREEN_HEIGHT;
} completion:^(BOOL finished) {
[self removeFromSuperview];
}];
}
-(NSMutableArray *)dataArray{
if (!_dataArray) {
_dataArray = [NSMutableArray array];
}
return _dataArray;
}
@end