From fa9af5ff1be54fa7b6153b84ba902cf21e698852 Mon Sep 17 00:00:00 2001 From: CodeST <694468528@qq.com> Date: Tue, 3 Feb 2026 14:05:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86=E8=81=8A=E5=A4=A9=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E6=B2=A1=E5=9B=9E=E6=9D=A5=20=20=E5=88=87=E5=88=80?= =?UTF-8?q?=E4=B8=8B=E4=B8=80=E4=B8=AAcollectionviewcell=20=EF=BC=8C?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E4=B8=8D=E5=AF=B9=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?=EF=BC=88=E7=A6=81=E7=94=A8=E6=BB=9A=E5=8A=A8=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- keyBoard/Class/AiTalk/VC/KBAIHomeVC.m | 38 ++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/keyBoard/Class/AiTalk/VC/KBAIHomeVC.m b/keyBoard/Class/AiTalk/VC/KBAIHomeVC.m index 37c041b..0e1c39a 100644 --- a/keyBoard/Class/AiTalk/VC/KBAIHomeVC.m +++ b/keyBoard/Class/AiTalk/VC/KBAIHomeVC.m @@ -82,6 +82,12 @@ @property (nonatomic, assign) NSInteger pendingAIRequestCount; +/// 是否处于语音流程中(录音/识别中,用于禁止滚动) +@property (nonatomic, assign) BOOL isVoiceProcessing; + +/// 是否正在语音录制中(用于禁止滚动) +@property (nonatomic, assign) BOOL isVoiceRecording; + /// 右上角消息按钮 @property (nonatomic, strong) UIButton *messageButton; @@ -491,8 +497,7 @@ - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView { if (self.isWaitingForAIResponse) { NSLog(@"[KBAIHomeVC] 正在等待 AI 回复,禁止滚动"); - scrollView.scrollEnabled = NO; - scrollView.scrollEnabled = YES; + [self updateCollectionViewScrollState]; } } @@ -641,6 +646,14 @@ #pragma mark - Private +- (void)updateCollectionViewScrollState { + BOOL shouldEnable = !self.isWaitingForAIResponse + && !self.isVoiceRecording + && !self.isVoiceProcessing; + self.collectionView.scrollEnabled = shouldEnable; + self.collectionView.panGestureRecognizer.enabled = shouldEnable; +} + - (void)updateChatViewBottomInset { CGFloat bottomInset; @@ -827,14 +840,23 @@ } - (void)voiceToTextManagerDidBeginRecording:(KBVoiceToTextManager *)manager { + self.isVoiceRecording = YES; + self.isVoiceProcessing = YES; + [self updateCollectionViewScrollState]; [self.voiceRecordManager startRecording]; } - (void)voiceToTextManagerDidEndRecording:(KBVoiceToTextManager *)manager { + self.isVoiceRecording = NO; + self.isVoiceProcessing = YES; + [self updateCollectionViewScrollState]; [self.voiceRecordManager stopRecording]; } - (void)voiceToTextManagerDidCancelRecording:(KBVoiceToTextManager *)manager { + self.isVoiceRecording = NO; + self.isVoiceProcessing = NO; + [self updateCollectionViewScrollState]; [self.voiceRecordManager cancelRecording]; } @@ -871,6 +893,8 @@ if (cell) { [cell updateLastUserMessage:KBLocalized(@"语音识别失败")]; } + strongSelf.isVoiceProcessing = NO; + [strongSelf updateCollectionViewScrollState]; return; } @@ -881,6 +905,8 @@ if (cell) { [cell removeLoadingUserMessage]; } + strongSelf.isVoiceProcessing = NO; + [strongSelf updateCollectionViewScrollState]; return; } @@ -888,6 +914,7 @@ [cell updateLastUserMessage:transcript]; } + strongSelf.isVoiceProcessing = NO; [strongSelf handleTranscribedText:transcript appendToUI:NO]; }); }]; @@ -901,6 +928,9 @@ - (void)voiceRecordManager:(KBVoiceRecordManager *)manager didFailWithError:(NSError *)error { NSLog(@"[KBAIHomeVC] 录音失败:%@", error.localizedDescription); + self.isVoiceRecording = NO; + self.isVoiceProcessing = NO; + [self updateCollectionViewScrollState]; } #pragma mark - Private @@ -931,7 +961,7 @@ self.pendingAIRequestCount += 1; self.isWaitingForAIResponse = (self.pendingAIRequestCount > 0); if (self.pendingAIRequestCount == 1) { - self.collectionView.scrollEnabled = NO; + [self updateCollectionViewScrollState]; NSLog(@"[KBAIHomeVC] 开始等待 AI 回复,禁止 CollectionView 滚动"); } @@ -950,7 +980,7 @@ } strongSelf.isWaitingForAIResponse = (strongSelf.pendingAIRequestCount > 0); if (strongSelf.pendingAIRequestCount == 0) { - strongSelf.collectionView.scrollEnabled = YES; + [strongSelf updateCollectionViewScrollState]; NSLog(@"[KBAIHomeVC] AI 回复完成,恢复 CollectionView 滚动"); }