// // QXRoomBottomView.m // QXLive // // Created by 启星 on 2025/6/7. // #import "QXRoomBottomView.h" #import "QXDynamicCommentInputView.h" #import "QXRoomMessageManager.h" #import "QXBadgeButton.h" #import "AppDelegate.h" @interface QXRoomBottomView() @property (nonatomic,strong)UIView *sayBg; @property (nonatomic,strong)UIImageView *sayImageView; @property (nonatomic,strong)UILabel *sayLabel; /// voice @property (nonatomic,strong)QXBadgeButton *playAudioBtn; @property (nonatomic,strong)QXBadgeButton *audioBtn; @property (nonatomic,strong)QXBadgeButton *messageBtn; @property (nonatomic,strong)QXBadgeButton *pkBtn; @property (nonatomic,strong)QXBadgeButton *musicBtn; @property (nonatomic,strong)QXBadgeButton *giftBtn; @property (nonatomic,strong)QXBadgeButton *setBtn; @property (nonatomic,strong)NSMutableArray *eventArray; @property (nonatomic,assign)QXRoomRoleType roleType; @property (nonatomic,strong)QXDynamicCommentInputView *commentView; @property (nonatomic,assign)QXRedPacketModel* redpacketModel; @end @implementation QXRoomBottomView - (instancetype)init { self = [super init]; if (self) { [self initSubviews]; } return self; } -(void)initSubviews{ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(noticeUnreadNumberDidChanged:) name:noticeUnreadNumberDidChanged object:nil]; MJWeakSelf [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil]; self.sayBg = [[UIView alloc] init]; self.sayBg.backgroundColor = RGB16A(0xffffff, 0.2); [self.sayBg addRoundedCornersWithRadius:18]; [self.sayBg addTapBlock:^(id _Nonnull obj) { if (weakSelf.roomModel.user_info.is_mute.intValue == 1) { showToast(@"您已被禁言"); return; } [weakSelf.vc.view addSubview:weakSelf.commentView]; [weakSelf.commentView.textField becomeFirstResponder]; }]; [self addSubview:self.sayBg]; [self.sayBg mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(16); make.top.equalTo(self); make.height.mas_equalTo(36); make.width.mas_equalTo(106); }]; self.sayImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"room_say_icon"]]; [self.sayBg addSubview:self.sayImageView]; [self.sayImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(10); make.centerY.equalTo(self.sayBg); make.width.height.mas_equalTo(24); }]; self.sayLabel = [[UILabel alloc] init]; self.sayLabel.textColor = [UIColor whiteColor]; self.sayLabel.font = [UIFont systemFontOfSize:14]; self.sayLabel.text = QXText(@"说点什么"); self.sayLabel.textAlignment = NSTextAlignmentCenter; [self.sayBg addSubview:self.sayLabel]; [self.sayLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.sayImageView.mas_right); make.centerY.equalTo(self.sayBg); make.right.equalTo(self.sayBg); }]; self.playAudioBtn = [[QXBadgeButton alloc] init]; self.playAudioBtn.tag = 20; [self.playAudioBtn setImage:[UIImage imageNamed:@"room_event_play_audio_nor"] forState:(UIControlStateNormal)]; [self.playAudioBtn setImage:[UIImage imageNamed:@"room_event_play_audio_sel"] forState:(UIControlStateSelected)]; [self.playAudioBtn addTarget:self action:@selector(eventAction:) forControlEvents:(UIControlEventTouchUpInside)]; self.playAudioBtn.hidden = YES; [self addSubview:self.playAudioBtn]; self.audioBtn = [[QXBadgeButton alloc] init]; self.audioBtn.tag = 21; [self.audioBtn setImage:[UIImage imageNamed:@"room_event_mute_audio_nor"] forState:(UIControlStateNormal)]; [self.audioBtn setImage:[UIImage imageNamed:@"room_event_mute_audio_sel"] forState:(UIControlStateSelected)]; [self.audioBtn addTarget:self action:@selector(eventAction:) forControlEvents:(UIControlEventTouchUpInside)];; self.audioBtn.hidden = YES; [self addSubview:self.audioBtn]; self.messageBtn = [[QXBadgeButton alloc] init]; self.messageBtn.tag = 22; AppDelegate *appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate; NSInteger unread = appDelegate.tabbarVC.messageUnReadNumber; [self.messageBtn.unreadView setNum:unread]; [self.messageBtn setImage:[UIImage imageNamed:@"room_event_message"] forState:(UIControlStateNormal)]; [self.messageBtn addTarget:self action:@selector(eventAction:) forControlEvents:(UIControlEventTouchUpInside)];; self.messageBtn.hidden = YES; [self addSubview:self.messageBtn]; self.pkBtn = [[QXBadgeButton alloc] init]; self.pkBtn.tag = 23; [self.pkBtn setImage:[UIImage imageNamed:@"room_event_pk"] forState:(UIControlStateNormal)]; [self.pkBtn addTarget:self action:@selector(eventAction:) forControlEvents:(UIControlEventTouchUpInside)];; self.pkBtn.hidden = YES; [self addSubview:self.pkBtn]; self.musicBtn = [[QXBadgeButton alloc] init]; self.musicBtn.tag = 24; [self.musicBtn setImage:[UIImage imageNamed:@"room_event_music"] forState:(UIControlStateNormal)]; [self.musicBtn addTarget:self action:@selector(eventAction:) forControlEvents:(UIControlEventTouchUpInside)];; self.musicBtn.hidden = YES; [self addSubview:self.musicBtn]; self.giftBtn = [[QXBadgeButton alloc] init]; self.giftBtn.tag = 25; [self.giftBtn setImage:[UIImage imageNamed:@"room_event_gift"] forState:(UIControlStateNormal)]; [self.giftBtn addTarget:self action:@selector(eventAction:) forControlEvents:(UIControlEventTouchUpInside)];; self.giftBtn.hidden = YES; [self addSubview:self.giftBtn]; self.setBtn = [[QXBadgeButton alloc] init]; self.setBtn.tag = 26; [self.setBtn setImage:[UIImage imageNamed:@"room_event_set"] forState:(UIControlStateNormal)]; [self.setBtn addTarget:self action:@selector(eventAction:) forControlEvents:(UIControlEventTouchUpInside)];; self.setBtn.hidden = YES; [self addSubview:self.setBtn]; } -(void)setRoomModel:(QXRoomModel *)roomModel{ _roomModel = roomModel; } -(void)setIsCabinRoom:(BOOL)isCabinRoom{ _isCabinRoom = isCabinRoom; [self.sayBg mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(16); make.top.equalTo(self); make.height.mas_equalTo(36); make.right.mas_equalTo(-16); }]; for (UIButton*btn in self.eventArray) { btn.hidden = YES; } } -(void)noticeUnreadNumberDidChanged:(NSNotification*)notice{ NSNumber *number = notice.object; [self.messageBtn.unreadView setNum:number.longValue]; } -(void)setRoleType:(QXRoomRoleType)roleType hasPK:(BOOL)hasPK hasSong:(BOOL)hasSong{ _roleType = roleType; /// 播放声音按钮 self.playAudioBtn.hidden = YES; /// 消息按钮 self.messageBtn.hidden = YES; /// pk按钮 self.pkBtn.hidden = YES; /// 点歌 self.musicBtn.hidden = YES; // 送礼物 self.giftBtn.hidden = YES; /// 设置 self.setBtn.hidden = YES; self.audioBtn.selected = NO; self.playAudioBtn.selected = NO; switch (roleType) { /// 主持人 case QXRoomRoleTypeCompere: { self.eventArray = [NSMutableArray arrayWithArray:@[ self.playAudioBtn, self.messageBtn, // self.musicBtn, self.giftBtn, self.setBtn, ]]; if (hasSong) { if (![self.eventArray containsObject:self.musicBtn]) { [self.eventArray insertObject:self.musicBtn atIndex:2]; } }else{ if ([self.eventArray containsObject:self.musicBtn]) { [self.eventArray removeObject:self.musicBtn]; } } if (hasPK) { if (![self.eventArray containsObject:self.pkBtn]) { [self.eventArray insertObject:self.pkBtn atIndex:2]; } }else{ if ([self.eventArray containsObject:self.pkBtn]) { [self.eventArray removeObject:self.pkBtn]; } } } break; /// 房主 case QXRoomRoleTypeOwner: { self.eventArray = [NSMutableArray arrayWithArray:@[ self.playAudioBtn, self.messageBtn, // self.musicBtn, self.giftBtn, self.setBtn, ]]; if (hasSong) { if (![self.eventArray containsObject:self.musicBtn]) { [self.eventArray insertObject:self.musicBtn atIndex:2]; } }else{ if ([self.eventArray containsObject:self.musicBtn]) { [self.eventArray removeObject:self.musicBtn]; } } if (hasPK) { if (![self.eventArray containsObject:self.pkBtn]) { [self.eventArray insertObject:self.pkBtn atIndex:2]; } }else{ if ([self.eventArray containsObject:self.pkBtn]) { [self.eventArray removeObject:self.pkBtn]; } } } break; // 观众 case QXRoomRoleTypeAudience: { self.eventArray = [NSMutableArray arrayWithArray:@[ self.playAudioBtn, self.messageBtn, // self.musicBtn, self.giftBtn, self.setBtn, ]]; if (hasSong) { if (![self.eventArray containsObject:self.musicBtn]) { [self.eventArray insertObject:self.musicBtn atIndex:2]; } }else{ if ([self.eventArray containsObject:self.musicBtn]) { [self.eventArray removeObject:self.musicBtn]; } } } break; default: break; } CGFloat btnWidth = 35; for ( int i = 0 ;i < self.eventArray.count;i++ ) { QXBadgeButton*btn = self.eventArray[i]; btn.hidden = NO; [btn mas_remakeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(-(16+btnWidth*(self.eventArray.count-(i+1)))); make.width.mas_equalTo(btnWidth); make.centerY.equalTo(self.sayBg); make.height.mas_equalTo(self.sayBg); }]; } } /// 1 麦下 2 麦上 -(void)setStatus:(NSInteger)status{ _status = status; // 播放声音 self.playAudioBtn.selected = NO; // 麦克风 self.audioBtn.selected = NO; if (_status == 1) { // 隐藏麦克风 self.audioBtn.hidden = YES; /// 查看数组中是否有麦克风按钮 if ([self.eventArray containsObject:self.audioBtn]) { /// 有就移除 [self.eventArray removeObject:self.audioBtn]; } }else if(_status == 2){ // 显示麦克风 self.audioBtn.hidden = NO; if (![self.eventArray containsObject:self.audioBtn]) { /// 当前数组中不包含麦克风 就插入到下标为1的 [self.eventArray insertObject:self.audioBtn atIndex:1]; } } CGFloat btnWidth = 35; for ( int i = 0 ;i < self.eventArray.count;i++ ) { QXBadgeButton*btn = self.eventArray[i]; btn.hidden = NO; [btn mas_remakeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(-(16+btnWidth*(self.eventArray.count-(i+1)))); make.width.mas_equalTo(btnWidth); make.centerY.equalTo(self.sayBg); make.height.mas_equalTo(self.sayBg); }]; } } -(void)setMuteAudioStatus:(BOOL)status{ self.audioBtn.selected = status; } -(void)setPlayAudioStatus:(BOOL)status{ self.playAudioBtn.selected = status; } -(void)eventAction:(UIButton*)sender{ if (sender == self.audioBtn) { if (self.roomModel.user_info.is_mute_pit.intValue == 1) { showToast(@"您已被禁麦"); return; } sender.selected = !sender.selected; } if (sender == self.playAudioBtn) { sender.selected = !sender.selected; } if (self.delegate && [self.delegate respondsToSelector:@selector(didClickEventType:isSelected:)]) { [self.delegate didClickEventType:sender.tag isSelected:sender.selected]; } } -(void)atUserWithName:(NSString *)nickname{ if (self.roomModel.user_info.is_mute.intValue == 1) { showToast(@"您已被禁言"); return; } self.commentView.textField.text = [NSString stringWithFormat:@"@%@ ",nickname]; [self.vc.view addSubview:self.commentView]; [self.commentView.textField becomeFirstResponder]; } -(void)inputMessageWithName:(NSString *)message redpacketModel:(QXRedPacketModel*)redpacketModel{ self.redpacketModel = redpacketModel; self.commentView.textField.text = [NSString stringWithFormat:@"#口令红包 %@",message]; [self.vc.view addSubview:self.commentView]; [self.commentView.textField becomeFirstResponder]; } #pragma mark - 发消息 -(void)didClickSendWithText:(NSString*)text model:(nonnull QXDynamicCommentListModel *)model{ if (self.roomModel.user_info.is_mute.intValue == 1) { showToast(@"您已被禁言"); [self.vc.view endEditing:YES]; return; } [[QXGlobal shareGlobal] finishTask]; [[QXRoomMessageManager shared] sendChatMessage:text messageType:(QXRoomMessageTypeText) needInsertMessage:YES]; self.commentView.textField.text = @""; if (self.redpacketModel == nil) { [self.vc.view endEditing:YES]; return; } NSString*password = [NSString stringWithFormat:@"#口令红包 %@",self.redpacketModel.password]; if ([text isEqualToString:password]) { if (self.delegate && [self.delegate respondsToSelector:@selector(didSendMessage:redpacketModel:)]) { [self.delegate didSendMessage:text redpacketModel:self.redpacketModel]; } } [self.vc.view endEditing:YES]; } - (void)keyboardWillHide:(NSNotification *)notification { [UIView animateWithDuration:0.3 animations:^{ self.commentView.y = SCREEN_HEIGHT; }completion:^(BOOL finished) { [self.commentView removeFromSuperview]; }]; } - (void)keyboardWillShow:(NSNotification *)notification { // CGRect keyboardFrame = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue]; // [UIView animateWithDuration:0.3 animations:^{ // self.commentView.y = keyboardFrame.origin.y+TabbarContentHeight; // }]; } - (void)keyboardWillChangeFrame:(NSNotification *)notification { CGRect keyboardFrame = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue]; [UIView animateWithDuration:0.15 animations:^{ self.commentView.y = keyboardFrame.origin.y-TabbarContentHeight; }]; } -(void)didResignFirstResponder{ self.redpacketModel = nil; } -(QXDynamicCommentInputView *)commentView{ if (!_commentView) { _commentView = [[QXDynamicCommentInputView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, TabbarContentHeight)]; _commentView.delegate = self; } return _commentView; } @end