Files
featherVoice/QXLive/Room(房间)/View/PK/QXRoomPKTimeSetView.m

230 lines
9.0 KiB
Mathematica
Raw Normal View History

2025-08-08 10:49:36 +08:00
//
// QXRoomPKTimeSetView.m
// QXLive
//
// Created by on 2025/7/3.
//
#import "QXRoomPKTimeSetView.h"
#import "QXSelectAuctionInfoView.h"
#import "QXMineNetwork.h"
@interface QXRoomPKTimeSetView()<UIGestureRecognizerDelegate,UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout,UITextFieldDelegate>
@property (nonatomic,strong)UIView *bgView;
@property (nonatomic,strong)UILabel *titleLabel;
@property (nonatomic,strong)UICollectionView *collectionView;
@property (nonatomic,strong)NSMutableArray *dataArray;
@property (nonatomic,strong)QXRoomRelationModel *timeModel;
@property (nonatomic,strong)UITextField *textField;
@property (nonatomic,strong)UIView *line;
@property (nonatomic,strong)UIButton *commitBtn;
@property (nonatomic,strong)UIButton *cancelBtn;
@end
@implementation QXRoomPKTimeSetView
- (instancetype)init
{
self = [super init];
if (self) {
self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
[self initSubviews];
}
return self;
}
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
return touch.view == self;
}
-(void)initSubviews{
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hide)];
tap.delegate = self;
[self addGestureRecognizer:tap];
self.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.3];
self.bgView = [[UIView alloc] initWithFrame:CGRectMake(0, ScaleWidth(144), SCREEN_WIDTH, ScaleWidth(429)+kSafeAreaBottom)];
self.bgView.backgroundColor = UIColor.whiteColor;
[self.bgView addRoundedCornersWithRadius:16 byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight)];
[self addSubview:self.bgView];
self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(16, 16, 300, 24)];
self.titleLabel.text = @"请选择PK时长";
self.titleLabel.font = [UIFont boldSystemFontOfSize:16];
self.titleLabel.textColor = [UIColor colorWithHexString:@"#333333"];
[self.bgView addSubview: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:CGRectMake(0, self.titleLabel.bottom+12, self.bgView.width,self.bgView.height-12-42-self.titleLabel.bottom ) 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];
QXRoomRelationModel *time1 = [[QXRoomRelationModel alloc] init];
time1.name = @"5分钟";
time1.relation_id = @"5";
[self.dataArray addObject:time1];
QXRoomRelationModel *time2 = [[QXRoomRelationModel alloc] init];
time2.name = @"10分钟";
time2.relation_id = @"10";
[self.dataArray addObject:time2];
QXRoomRelationModel *time3 = [[QXRoomRelationModel alloc] init];
time3.name = @"15分钟";
time3.relation_id = @"15";
[self.dataArray addObject:time3];
QXRoomRelationModel *time4 = [[QXRoomRelationModel alloc] init];
time4.name = @"20分钟";
time4.relation_id = @"20";
[self.dataArray addObject:time4];
QXRoomRelationModel *time5 = [[QXRoomRelationModel alloc] init];
time5.name = @"25分钟";
time5.relation_id = @"25";
[self.dataArray addObject:time5];
QXRoomRelationModel *time6 = [[QXRoomRelationModel alloc] init];
time6.name = @"30分钟";
time6.relation_id = @"30";
[self.dataArray addObject:time6];
QXRoomRelationModel *time7 = [[QXRoomRelationModel alloc] init];
time7.name = @"35分钟";
time7.relation_id = @"35";
[self.dataArray addObject:time7];
QXRoomRelationModel *time8 = [[QXRoomRelationModel alloc] init];
time8.name = @"40分钟";
time8.relation_id = @"40";
[self.dataArray addObject:time8];
// self.textField = [[UITextField alloc] initWithFrame:CGRectMake(16, self.collectionView.bottom+10, self.bgView.width-32, 30)];
// self.textField.font = [UIFont systemFontOfSize:14];
// self.textField.textColor = RGB16(0x333333);
// self.textField.placeholder = @"请输入自定义时间最少5分钟";
// self.textField.delegate = self;
// self.textField.returnKeyType = UIReturnKeyDone;
// [self.bgView addSubview:self.textField];
//
// self.line = [[UIView alloc] initWithFrame:CGRectMake(16, self.textField.bottom, self.bgView.width-32, 1)];
// self.line.backgroundColor = RGB16(0x999999);
// [self.bgView addSubview:self.line];
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(cancelAction) 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];
}
-(void)commitAction{
if (self.timeModel == nil) {
showToast(@"请选择PK时长");
return;
}
MJWeakSelf
[QXMineNetwork roomPkStartWithPk_id:self.pkId pk_times:self.timeModel.relation_id successBlock:^(NSDictionary * _Nonnull dict) {
[weakSelf hide];
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
showToast(msg);
}];
}
-(void)cancelAction{
[self hide];
}
#pragma mark - UITextFieldDelegate
//-(BOOL)textFieldShouldReturn:(UITextField *)textField{
// [textField resignFirstResponder];
// return YES;
//}
//-(void)textFieldDidBeginEditing:(UITextField *)textField{
// [UIView animateWithDuration:0.3 animations:^{
// self.bgView.y = kSafeAreaTop+90;
// } completion:^(BOOL finished) {
//
// }];
//}
//-(void)textFieldDidEndEditing:(UITextField *)textField{
// [UIView animateWithDuration:0.3 animations:^{
// self.bgView.y = SCREEN_HEIGHT-ScaleWidth(429);
// } completion:^(BOOL finished) {
//
// }];
//}
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
return 1;
}
-(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;
}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
CGFloat width = (SCREEN_WIDTH-16*2-12*3)/4;
return CGSizeMake(width, 44);
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
QXRoomRelationModel *model = self.dataArray[indexPath.row];
if (model.isSelected) {
return;
}
self.timeModel.isSelected = NO;
model.isSelected = YES;
self.timeModel = model;
[collectionView reloadData];
}
-(NSMutableArray *)dataArray{
if (!_dataArray) {
_dataArray = [NSMutableArray array];
}
return _dataArray;
}
-(void)showInView:(UIView *)view{
self.bgView.y = SCREEN_HEIGHT;
[view addSubview:self];
[UIView animateWithDuration:0.3 animations:^{
self.bgView.y = SCREEN_HEIGHT-ScaleWidth(429)-kSafeAreaBottom;
}];
}
-(void)hide{
[UIView animateWithDuration:0.3 animations:^{
self.bgView.y = SCREEN_HEIGHT;
} completion:^(BOOL finished) {
[self removeFromSuperview];
}];
}
@end