// // QXRoomBarCabinListView.m // QXLive // // Created by 启星 on 2026/1/5. // #import "QXRoomBarCabinListView.h" #import "QXRoomBarCabinListCell.h" #import "QXMineNetwork.h" @interface QXRoomBarCabinListView() @property (nonatomic,strong)UIView *bgView; @property (nonatomic,strong)UILabel *titleLabel; @property (nonatomic,strong)UICollectionView *collectionView; @property (nonatomic,strong)NSMutableArray *dataArray; @end @implementation QXRoomBarCabinListView - (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]; UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; // layout.minimumLineSpacing = 20; // layout.minimumInteritemSpacing = 20; layout.sectionInset = UIEdgeInsetsMake(0, 50, 0, 50); layout.scrollDirection = UICollectionViewScrollDirectionVertical; self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, self.titleLabel.bottom+10, self.bgView.width, self.bgView.height-self.titleLabel.bottom-20) collectionViewLayout:layout]; [self.collectionView registerNib:[UINib nibWithNibName:@"QXRoomBarCabinListCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"QXRoomBarCabinListCell"]; 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]; } -(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{ return touch.view == self; } -(void)getGiftList{ MJWeakSelf // [QXMineNetwork giftListWithLabel:@"99" roomId:self.roomId successBlock:^(NSArray * _Nonnull list) { // [weakSelf.dataArray removeAllObjects]; // [weakSelf.dataArray addObjectsFromArray:list]; // [weakSelf.collectionView reloadData]; // } failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) { // // }]; [QXMineNetwork roomBarCabinRoomListWithRoomId:self.roomId successBlock:^(NSArray * _Nonnull list) { [weakSelf.dataArray removeAllObjects]; [weakSelf.dataArray addObjectsFromArray:list]; [weakSelf.collectionView reloadData]; } failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) { }]; } -(void)setRoomId:(NSString *)roomId{ _roomId = roomId; } -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ return self.dataArray.count; } -(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ QXRoomBarCabinListCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QXRoomBarCabinListCell" forIndexPath:indexPath]; // cell.model = self.dataArray[indexPath.row]; return cell; } - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{ return CGSizeMake(ScaleWidth(128), ScaleWidth(128)); } -(NSMutableArray *)dataArray{ if (!_dataArray) { _dataArray = [NSMutableArray array]; } return _dataArray; } -(void)showInView:(UIView *)view{ [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