228 lines
9.0 KiB
Mathematica
228 lines
9.0 KiB
Mathematica
|
|
//
|
||
|
|
// QXRoomPKSearchView.m
|
||
|
|
// QXLive
|
||
|
|
//
|
||
|
|
// Created by 启星 on 2025/7/2.
|
||
|
|
//
|
||
|
|
|
||
|
|
#import "QXRoomPKSearchView.h"
|
||
|
|
#import "QXMineNetwork.h"
|
||
|
|
#import "QXAddDirectCell.h"
|
||
|
|
#import "UIButton+QX.h"
|
||
|
|
#import "QXRoomPKSetView.h"
|
||
|
|
|
||
|
|
@interface QXRoomPKSearchView()<UIGestureRecognizerDelegate,UITextFieldDelegate,UITableViewDelegate,UITableViewDataSource,QXDirectDelegate>
|
||
|
|
@property (nonatomic,strong)UIView *bgView;
|
||
|
|
@property (nonatomic,strong)UILabel *titleLabel;
|
||
|
|
@property (nonatomic,strong)UIButton *setBtn;
|
||
|
|
@property (nonatomic,strong)UIButton *pkBtn;
|
||
|
|
@property (nonatomic,strong)UIView *seachBgView;
|
||
|
|
@property (nonatomic,strong)UIImageView *searchImageView;
|
||
|
|
@property (nonatomic,strong)UITextField *textField;
|
||
|
|
|
||
|
|
@property (nonatomic,strong)UILabel*sectionLabel;
|
||
|
|
@property (nonatomic,strong)UITableView*tableView;
|
||
|
|
@property (nonatomic,strong)NSMutableArray*dataArray;
|
||
|
|
@property (nonatomic,assign)NSInteger page;
|
||
|
|
|
||
|
|
@property (nonatomic,strong)QXRoomPKSetView *pkSetView;
|
||
|
|
@end
|
||
|
|
@implementation QXRoomPKSearchView
|
||
|
|
- (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 = @"发起直播对战";
|
||
|
|
self.titleLabel.font = [UIFont boldSystemFontOfSize:16];
|
||
|
|
self.titleLabel.textColor = [UIColor colorWithHexString:@"#333333"];
|
||
|
|
[self.bgView addSubview:self.titleLabel];
|
||
|
|
|
||
|
|
self.setBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.bgView.width-50-6, 7, 50, 44)];
|
||
|
|
[self.setBtn setTitle:@"设置" forState:(UIControlStateNormal)];
|
||
|
|
self.setBtn.titleLabel.font = [UIFont systemFontOfSize:12];
|
||
|
|
[self.setBtn setTitleColor:RGB16(0x999999) forState:(UIControlStateNormal)];
|
||
|
|
[self.setBtn setImage:[[UIImage imageNamed:@"arrowRight"] imageByTintColor:RGB16(0x999999)] forState:(UIControlStateNormal)];
|
||
|
|
[self.setBtn qx_layoutButtonNOSizeToFitWithEdgeInsetsStyle:(QXButtonEdgeInsetsStyleRight) imageTitleSpace:2];
|
||
|
|
[self.setBtn addTarget:self action:@selector(setAction) forControlEvents:(UIControlEventTouchUpInside)];
|
||
|
|
[self.bgView addSubview:self.setBtn];
|
||
|
|
|
||
|
|
self.pkBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.bgView.width-50-16, self.titleLabel.bottom+12, 50, 35)];
|
||
|
|
[self.pkBtn setBackgroundImage:[UIImage imageNamed:@"room_pk_random_icon"] forState:(UIControlStateNormal)];
|
||
|
|
[self.pkBtn addTarget:self action:@selector(pkAction) forControlEvents:(UIControlEventTouchUpInside)];
|
||
|
|
[self.bgView addSubview:self.pkBtn];
|
||
|
|
|
||
|
|
|
||
|
|
self.seachBgView = [[UIView alloc] initWithFrame:CGRectMake(16, self.titleLabel.bottom+12, SCREEN_WIDTH-16-74, 35)];
|
||
|
|
self.seachBgView.backgroundColor = [UIColor colorWithHexString:@"#EFF2F8"];
|
||
|
|
self.seachBgView.layer.masksToBounds = YES;
|
||
|
|
self.seachBgView.layer.cornerRadius = 17.5;
|
||
|
|
[self.bgView addSubview:self.seachBgView];
|
||
|
|
|
||
|
|
self.searchImageView = [[UIImageView alloc] initWithFrame:CGRectMake(8, 5.5, 24, 24)];
|
||
|
|
self.searchImageView.image = [UIImage imageNamed:@"room_song_search"];
|
||
|
|
[self.seachBgView addSubview:self.searchImageView];
|
||
|
|
|
||
|
|
self.textField = [[UITextField alloc] initWithFrame:CGRectMake(self.searchImageView.right+6, 0, self.seachBgView.width-self.searchImageView.right-6-8, 35)];
|
||
|
|
self.textField.placeholder = @"请根据房间ID搜索";
|
||
|
|
self.textField.font = [UIFont systemFontOfSize:14];
|
||
|
|
[self.textField addTarget:self action:@selector(textDidChange:) forControlEvents:(UIControlEventEditingChanged)];
|
||
|
|
self.textField.returnKeyType = UIReturnKeyDone;
|
||
|
|
self.textField.delegate = self;
|
||
|
|
self.textField.textColor = [UIColor colorWithHexString:@"#333333"];
|
||
|
|
[self.seachBgView addSubview:self.textField];
|
||
|
|
|
||
|
|
|
||
|
|
self.sectionLabel = [[UILabel alloc] initWithFrame:CGRectMake(16, self.seachBgView.bottom+5, 300, 20)];
|
||
|
|
self.sectionLabel.text = @"为你推荐";
|
||
|
|
self.sectionLabel.font = [UIFont boldSystemFontOfSize:16];
|
||
|
|
self.sectionLabel.textColor = [UIColor colorWithHexString:@"#333333"];
|
||
|
|
[self.bgView addSubview:self.sectionLabel];
|
||
|
|
|
||
|
|
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, self.sectionLabel.bottom+5, self.width, self.bgView.height-5-self.sectionLabel.bottom) style:(UITableViewStylePlain)];
|
||
|
|
if (@available(iOS 15.0, *)) {
|
||
|
|
self.tableView.sectionHeaderTopPadding = 0;
|
||
|
|
} else {
|
||
|
|
// Fallback on earlier versions
|
||
|
|
}
|
||
|
|
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
|
||
|
|
self.tableView.tableFooterView = [UIView new];
|
||
|
|
self.tableView.delegate = self;
|
||
|
|
self.tableView.dataSource = self;
|
||
|
|
[self.bgView addSubview:self.tableView];
|
||
|
|
MJWeakSelf
|
||
|
|
[QXMineNetwork roomPkSearchWithRoomId:@"" page:1 successBlock:^(NSArray<QXRoomListModel *> * _Nonnull list) {
|
||
|
|
[weakSelf.dataArray removeAllObjects];
|
||
|
|
[weakSelf.dataArray addObjectsFromArray:list];
|
||
|
|
[weakSelf.tableView reloadData];
|
||
|
|
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
|
||
|
|
|
||
|
|
}];
|
||
|
|
}
|
||
|
|
|
||
|
|
-(void)setAction{
|
||
|
|
[self hide];
|
||
|
|
[self.pkSetView showInView:self.viewController.view];
|
||
|
|
}
|
||
|
|
-(void)pkAction{
|
||
|
|
[self hide];
|
||
|
|
[self sendPKWithRoomId:@""];;
|
||
|
|
}
|
||
|
|
|
||
|
|
-(void)textDidChange:(UITextField*)textField{
|
||
|
|
MJWeakSelf
|
||
|
|
self.sectionLabel.hidden = YES;
|
||
|
|
self.page = 1;
|
||
|
|
[QXMineNetwork roomPkSearchWithRoomId:textField.text page:self.page successBlock:^(NSArray<QXRoomListModel *> * _Nonnull list) {
|
||
|
|
[weakSelf.dataArray removeAllObjects];
|
||
|
|
[weakSelf.dataArray addObjectsFromArray:list];
|
||
|
|
[weakSelf.tableView reloadData];
|
||
|
|
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
|
||
|
|
|
||
|
|
}];
|
||
|
|
}
|
||
|
|
#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) {
|
||
|
|
|
||
|
|
}];
|
||
|
|
}
|
||
|
|
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
|
||
|
|
return YES;
|
||
|
|
}
|
||
|
|
|
||
|
|
#pragma mark - UITableViewDelegate,UITableViewDataSource
|
||
|
|
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
|
||
|
|
return self.dataArray.count;
|
||
|
|
}
|
||
|
|
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
|
||
|
|
QXAddDirectCell *cell = [QXAddDirectCell cellWithTableView:tableView];
|
||
|
|
QXRoomListModel *model = self.dataArray[indexPath.row];
|
||
|
|
cell.roomModel = model;
|
||
|
|
cell.delegate = self;
|
||
|
|
return cell;
|
||
|
|
}
|
||
|
|
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
|
||
|
|
return 52;
|
||
|
|
}
|
||
|
|
|
||
|
|
- (void)sendPKWithRoomId:(NSString *)roomId{
|
||
|
|
MJWeakSelf
|
||
|
|
[QXMineNetwork roomSendPkRoomId:self.roomId create_user_id:[QXGlobal shareGlobal].loginModel.user_id room_id_b:roomId successBlock:^(NSDictionary * _Nonnull dict) {
|
||
|
|
[weakSelf hide];
|
||
|
|
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
|
||
|
|
showToast(msg);
|
||
|
|
}];
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
-(void)showInView:(UIView *)view{
|
||
|
|
MJWeakSelf
|
||
|
|
[QXMineNetwork roomPkSearchWithRoomId:@"" page:1 successBlock:^(NSArray<QXRoomListModel *> * _Nonnull list) {
|
||
|
|
[weakSelf.dataArray removeAllObjects];
|
||
|
|
[weakSelf.dataArray addObjectsFromArray:list];
|
||
|
|
[weakSelf.tableView reloadData];
|
||
|
|
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
|
||
|
|
|
||
|
|
}];
|
||
|
|
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];
|
||
|
|
}];
|
||
|
|
}
|
||
|
|
-(NSMutableArray *)dataArray{
|
||
|
|
if (!_dataArray) {
|
||
|
|
_dataArray = [NSMutableArray array];
|
||
|
|
}
|
||
|
|
return _dataArray;
|
||
|
|
}
|
||
|
|
-(QXRoomPKSetView *)pkSetView{
|
||
|
|
if (!_pkSetView) {
|
||
|
|
_pkSetView = [[QXRoomPKSetView alloc] init];
|
||
|
|
}
|
||
|
|
return _pkSetView;
|
||
|
|
}
|
||
|
|
@end
|