// // QXRoomSeatSettingView.m // QXLive // // Created by 启星 on 2025/6/23. // #import "QXRoomSeatSettingView.h" #import "QXMineNetwork.h" @interface QXRoomSeatSettingView() @property (nonatomic,strong)UITableView *tableView; @property (nonatomic,strong)UIView *bgView; @end @implementation QXRoomSeatSettingView - (instancetype)init { self = [super init]; if (self) { self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); [self initSubviews]; } return self; } -(void)initSubviews{ self.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.3]; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hide)]; tap.delegate = self; [self addGestureRecognizer:tap]; self.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.3]; // ScaleWidth(126) self.bgView = [[UIView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-ScaleWidth(172))/2.0, (SCREEN_HEIGHT - ScaleWidth(126))/2.0, ScaleWidth(172), ScaleWidth(84))]; self.bgView.backgroundColor = UIColor.whiteColor; [self.bgView addRoundedCornersWithRadius:16]; [self addSubview:self.bgView]; self.tableView = [[UITableView alloc] initWithFrame:self.bgView.bounds style:(UITableViewStyleGrouped)]; self.tableView.backgroundColor = [UIColor clearColor]; self.tableView.dataSource = self; self.tableView.delegate = self; self.tableView.rowHeight =ScaleWidth(84)/2; self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; [self.bgView addSubview:self.tableView]; } -(void)setPitModel:(QXRoomPitModel *)pitModel{ _pitModel = pitModel; [self.tableView reloadData]; } -(void)setIsNoHaveLockMic:(BOOL)isNoHaveLockMic{ _isNoHaveLockMic = isNoHaveLockMic; self.bgView.height = ScaleWidth(42); self.tableView.height = ScaleWidth(42); [self.tableView reloadData]; } -(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{ return touch.view == self; } -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{ return [UIView new];; } -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ return 0.01; } -(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{ return [UIView new];; } -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{ return 0.01; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ // return 3; if (self.isNoHaveLockMic) { return 1; } return 2; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ QXRoomSeatSettingCell *cell = [QXRoomSeatSettingCell cellWithTableView:tableView]; cell.roomId = self.roomId; cell.pitModel = self.pitModel; if (self.isNoHaveLockMic) { cell.settingType = QXRoomSeatSettingHugMic; }else{ if (indexPath.row == 0) { // cell.isOn = self.pitModel.is_mute.intValue == 1; // cell.settingType = QXRoomSeatSettingMuteMic; cell.isOn = self.pitModel.is_lock.intValue == 1; cell.settingType = QXRoomSeatSettingLockMic; } // else if(indexPath.row == 1){ // cell.isOn = self.pitModel.is_lock.intValue == 1; // cell.settingType = QXRoomSeatSettingLockMic; // } else{ cell.settingType = QXRoomSeatSettingHugMic; } } MJWeakSelf cell.setSuccessBlock = ^(QXRoomPitModel * _Nonnull pitModel) { weakSelf.setSuccessBlock(pitModel); }; return cell; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ if (self.isNoHaveLockMic) { [self hide]; if (self.clickHugBlock) { self.clickHugBlock(self.pitModel); } return; } if (indexPath.row == 1) { [self hide]; if (self.clickHugBlock) { self.clickHugBlock(self.pitModel); } } } -(void)showInView:(UIView *)view{ self.bgView.alpha = 0; [view addSubview:self]; [UIView animateWithDuration:0.15 animations:^{ self.bgView.alpha = 1; }]; } -(void)hide{ [UIView animateWithDuration:0.15 animations:^{ self.bgView.alpha = 0; } completion:^(BOOL finished) { [self removeFromSuperview]; }]; } @end @implementation QXRoomSeatSettingCell + (instancetype)cellWithTableView:(UITableView *)tableView{ static NSString *cellId = @"QXRoomSeatSettingCell"; QXRoomSeatSettingCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId]; if (!cell) { cell = [[QXRoomSeatSettingCell alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:cellId]; } return cell; } - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{ if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { [self initSubViews]; self.backgroundColor = UIColor.clearColor; self.contentView.backgroundColor = UIColor.clearColor; self.selectionStyle = UITableViewCellSelectionStyleNone; } return self; } -(void)initSubViews{ self.titleLabel = [[UILabel alloc] init]; self.titleLabel.textColor = QXConfig.textColor; self.titleLabel.font = [UIFont systemFontOfSize:14]; [self.contentView addSubview:self.titleLabel]; [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(12); make.size.mas_equalTo(CGSizeMake(60, 21)); make.centerY.equalTo(self.contentView); }]; self.eventSwitch = [[UISwitch alloc] init]; self.eventSwitch.backgroundColor = RGB16A(0xffffff, 0.2); [self.eventSwitch addRoundedCornersWithRadius:12.5]; self.eventSwitch.onTintColor = QXConfig.themeColor; self.eventSwitch.thumbTintColor = [UIColor whiteColor]; [self.eventSwitch addTarget:self action:@selector(eventSwitch:) forControlEvents:(UIControlEventValueChanged)]; [self.contentView addSubview:self.eventSwitch]; [self.eventSwitch mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(-12); make.centerY.equalTo(self.contentView); }]; } -(void)setIsOn:(BOOL)isOn{ _isOn = isOn; [self.eventSwitch setOn:isOn animated:YES]; } -(void)setSettingType:(QXRoomSeatSettingType)settingType{ _settingType = settingType; switch (settingType) { case QXRoomSeatSettingMuteMic:{ self.eventSwitch.hidden = NO; self.titleLabel.text = @"禁麦"; } break; case QXRoomSeatSettingLockMic:{ self.eventSwitch.hidden = NO; self.titleLabel.text = @"锁麦"; } break; case QXRoomSeatSettingHugMic:{ self.eventSwitch.hidden = YES; self.titleLabel.text = @"抱麦"; } break; default: break; } } -(void)eventSwitch:(UISwitch*)sender{ BOOL isLock = NO; if (self.settingType == QXRoomSeatSettingMuteMic || self.settingType == QXRoomSeatSettingHugMic) { isLock = NO; }else{ isLock = YES; } MJWeakSelf BOOL isOn = sender.isOn; [QXMineNetwork roomPitLockOrMuteIsLock:isLock roomId:self.roomId pit_number:self.pitModel.pit_number.integerValue is_mute:isOn successBlock:^(NSDictionary * _Nonnull dict) { if (isOn) { [sender setOn:YES animated:YES]; }else{ [sender setOn:NO animated:YES]; } if (isLock) { weakSelf.pitModel.is_lock = isOn?@"1":@"0"; }else{ weakSelf.pitModel.is_mute = isOn?@"1":@"0"; } if (weakSelf.setSuccessBlock) { weakSelf.setSuccessBlock(weakSelf.pitModel); } } failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) { [self.eventSwitch setOn:self.isOn animated:YES]; }]; } @end