197 lines
8.0 KiB
Objective-C
197 lines
8.0 KiB
Objective-C
//
|
|
// QXSignShowTimeView.m
|
|
// QXLive
|
|
//
|
|
// Created by 启星 on 2025/11/25.
|
|
//
|
|
|
|
#import "QXSignShowTimeView.h"
|
|
#import "QXSelectAuctionInfoView.h"
|
|
#import "QXMineNetwork.h"
|
|
|
|
@interface QXSignShowTimeView()<UIGestureRecognizerDelegate,UICollectionViewDelegate,UICollectionViewDataSource>
|
|
@property (nonatomic,strong)UIView *bgView;
|
|
@property (nonatomic,strong)UILabel *titleLabel;
|
|
@property (nonatomic,strong)UICollectionView *collectionView;
|
|
@property (nonatomic,strong)UIButton *commitBtn;
|
|
@property (nonatomic,strong)UIButton *cancelBtn;
|
|
@property (nonatomic,strong)NSMutableArray *dataArray;
|
|
@property (nonatomic,strong)QXRoomRelationModel *selectedModel;
|
|
@end
|
|
@implementation QXSignShowTimeView
|
|
- (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(310)+kSafeAreaBottom)];
|
|
self.bgView.backgroundColor = RGB16(0xffffff);
|
|
[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 systemFontOfSize:16];
|
|
self.titleLabel.textColor = RGB16(0x333333);
|
|
self.titleLabel.textAlignment = NSTextAlignmentLeft;
|
|
self.titleLabel.text = @"展示才艺";
|
|
[self.bgView addSubview:self.titleLabel];
|
|
|
|
self.cancelBtn = [[UIButton alloc] initWithFrame:CGRectMake(38, self.bgView.height-kSafeAreaBottom-12-42, 95, 42)];
|
|
[self.cancelBtn setTitle:@"取消" forState:(UIControlStateNormal)];
|
|
self.cancelBtn.titleLabel.font = [UIFont systemFontOfSize:14];
|
|
[self.cancelBtn setTitleColor:QXConfig.btnTextColor forState:(UIControlStateNormal)];
|
|
self.cancelBtn.backgroundColor = RGB16(0x333333);
|
|
[self.cancelBtn addRoundedCornersWithRadius:21];
|
|
[self.cancelBtn addTarget:self action:@selector(cancelAction) forControlEvents:(UIControlEventTouchUpInside)];
|
|
[self.bgView addSubview:self.cancelBtn];
|
|
|
|
self.commitBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.cancelBtn.right+16, self.bgView.height-kSafeAreaBottom-12-42, self.bgView.width-self.cancelBtn.right-16-38, 42)];
|
|
[self.commitBtn setTitle:@"确定" forState:(UIControlStateNormal)];
|
|
self.commitBtn.titleLabel.font = [UIFont systemFontOfSize:14];
|
|
[self.commitBtn setTitleColor:QXConfig.btnTextColor forState:(UIControlStateNormal)];
|
|
self.commitBtn.backgroundColor = QXConfig.themeColor;
|
|
[self.commitBtn addRoundedCornersWithRadius:21];
|
|
[self.commitBtn addTarget:self action:@selector(commitAction) forControlEvents:(UIControlEventTouchUpInside)];
|
|
[self.bgView addSubview:self.commitBtn];
|
|
|
|
|
|
|
|
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
|
|
layout.minimumLineSpacing = 12;
|
|
layout.minimumInteritemSpacing = 12;
|
|
layout.sectionInset = UIEdgeInsetsMake(0, 16, 0, 16);
|
|
NSInteger itemWidth = (SCREEN_WIDTH-16*2-12*3)/4;
|
|
layout.itemSize = CGSizeMake(itemWidth, 44);
|
|
layout.scrollDirection = UICollectionViewScrollDirectionVertical;
|
|
self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, self.titleLabel.bottom+10, self.bgView.width, self.commitBtn.top-self.titleLabel.bottom-20) collectionViewLayout:layout];
|
|
[self.collectionView registerClass:[QXSelectAuctionInfoCell class] forCellWithReuseIdentifier:@"QXSelectAuctionInfoCell"];
|
|
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)setRoomId:(NSString *)roomId{
|
|
_roomId = roomId;
|
|
}
|
|
-(void)commitAction{
|
|
if (self.selectedModel == nil) {
|
|
showToast(@"请选择您要展示的才艺");
|
|
return;
|
|
}
|
|
[[QXRoomMessageManager shared] sendChatMessage:[NSString stringWithFormat:@"选择的才艺是 %@",self.selectedModel.name] messageType:(QXRoomMessageTypeText) needInsertMessage:YES];
|
|
[self hide];
|
|
}
|
|
|
|
-(void)getPlayList{
|
|
MJWeakSelf
|
|
[QXMineNetwork signGeyPlayListSuccessBlock:^(NSArray * _Nonnull list) {
|
|
[weakSelf.dataArray removeAllObjects];
|
|
for (NSString*title in list) {
|
|
QXRoomRelationModel *md = [[QXRoomRelationModel alloc] init];
|
|
md.name = title;
|
|
[weakSelf.dataArray addObject:md];
|
|
}
|
|
[weakSelf.collectionView reloadData];
|
|
} 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{
|
|
QXSelectAuctionInfoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QXSelectAuctionInfoCell" forIndexPath:indexPath];
|
|
cell.timeModel = self.dataArray[indexPath.row];
|
|
return cell;
|
|
}
|
|
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
|
|
QXRoomRelationModel *model = self.dataArray[indexPath.row];
|
|
if (model.isSelected) {
|
|
return;
|
|
}
|
|
self.selectedModel.isSelected = NO;
|
|
model.isSelected = YES;
|
|
self.selectedModel = model;
|
|
[collectionView reloadData];
|
|
}
|
|
-(void)cancelAction{
|
|
[self hide];
|
|
}
|
|
-(void)showInView:(UIView *)view{
|
|
self.selectedModel = nil;
|
|
[self.collectionView reloadData];
|
|
[self getPlayList];
|
|
self.bgView.y = SCREEN_HEIGHT;
|
|
[view addSubview:self];
|
|
[UIView animateWithDuration:0.3 animations:^{
|
|
self.bgView.y = SCREEN_HEIGHT-ScaleWidth(310)-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 中访问或设置其他属性
|
|
}];
|
|
}
|
|
-(NSMutableArray *)dataArray{
|
|
if (!_dataArray) {
|
|
_dataArray = [NSMutableArray array];
|
|
// QXRoomRelationModel *md = [[QXRoomRelationModel alloc] init];
|
|
// md.name = @"唱歌";
|
|
// [_dataArray addObject:md];
|
|
//
|
|
// QXRoomRelationModel *md1 = [[QXRoomRelationModel alloc] init];
|
|
// md1.name = @"唱歌";
|
|
// [_dataArray addObject:md1];
|
|
//
|
|
// QXRoomRelationModel *md2 = [[QXRoomRelationModel alloc] init];
|
|
// md2.name = @"唱歌";
|
|
// [_dataArray addObject:md2];
|
|
//
|
|
// QXRoomRelationModel *md3 = [[QXRoomRelationModel alloc] init];
|
|
// md3.name = @"唱歌";
|
|
// [_dataArray addObject:md3];
|
|
//
|
|
// QXRoomRelationModel *md4 = [[QXRoomRelationModel alloc] init];
|
|
// md4.name = @"唱歌";
|
|
// [_dataArray addObject:md4];
|
|
}
|
|
return _dataArray;
|
|
}
|
|
@end
|