处理聊天信息没回来 切刀下一个collectionviewcell ,信息不对的问题(禁用滚动)
This commit is contained in:
@@ -82,6 +82,12 @@
|
|||||||
|
|
||||||
@property (nonatomic, assign) NSInteger pendingAIRequestCount;
|
@property (nonatomic, assign) NSInteger pendingAIRequestCount;
|
||||||
|
|
||||||
|
/// 是否处于语音流程中(录音/识别中,用于禁止滚动)
|
||||||
|
@property (nonatomic, assign) BOOL isVoiceProcessing;
|
||||||
|
|
||||||
|
/// 是否正在语音录制中(用于禁止滚动)
|
||||||
|
@property (nonatomic, assign) BOOL isVoiceRecording;
|
||||||
|
|
||||||
/// 右上角消息按钮
|
/// 右上角消息按钮
|
||||||
@property (nonatomic, strong) UIButton *messageButton;
|
@property (nonatomic, strong) UIButton *messageButton;
|
||||||
|
|
||||||
@@ -491,8 +497,7 @@
|
|||||||
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
|
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
|
||||||
if (self.isWaitingForAIResponse) {
|
if (self.isWaitingForAIResponse) {
|
||||||
NSLog(@"[KBAIHomeVC] 正在等待 AI 回复,禁止滚动");
|
NSLog(@"[KBAIHomeVC] 正在等待 AI 回复,禁止滚动");
|
||||||
scrollView.scrollEnabled = NO;
|
[self updateCollectionViewScrollState];
|
||||||
scrollView.scrollEnabled = YES;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -641,6 +646,14 @@
|
|||||||
|
|
||||||
#pragma mark - Private
|
#pragma mark - Private
|
||||||
|
|
||||||
|
- (void)updateCollectionViewScrollState {
|
||||||
|
BOOL shouldEnable = !self.isWaitingForAIResponse
|
||||||
|
&& !self.isVoiceRecording
|
||||||
|
&& !self.isVoiceProcessing;
|
||||||
|
self.collectionView.scrollEnabled = shouldEnable;
|
||||||
|
self.collectionView.panGestureRecognizer.enabled = shouldEnable;
|
||||||
|
}
|
||||||
|
|
||||||
- (void)updateChatViewBottomInset {
|
- (void)updateChatViewBottomInset {
|
||||||
CGFloat bottomInset;
|
CGFloat bottomInset;
|
||||||
|
|
||||||
@@ -827,14 +840,23 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)voiceToTextManagerDidBeginRecording:(KBVoiceToTextManager *)manager {
|
- (void)voiceToTextManagerDidBeginRecording:(KBVoiceToTextManager *)manager {
|
||||||
|
self.isVoiceRecording = YES;
|
||||||
|
self.isVoiceProcessing = YES;
|
||||||
|
[self updateCollectionViewScrollState];
|
||||||
[self.voiceRecordManager startRecording];
|
[self.voiceRecordManager startRecording];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)voiceToTextManagerDidEndRecording:(KBVoiceToTextManager *)manager {
|
- (void)voiceToTextManagerDidEndRecording:(KBVoiceToTextManager *)manager {
|
||||||
|
self.isVoiceRecording = NO;
|
||||||
|
self.isVoiceProcessing = YES;
|
||||||
|
[self updateCollectionViewScrollState];
|
||||||
[self.voiceRecordManager stopRecording];
|
[self.voiceRecordManager stopRecording];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)voiceToTextManagerDidCancelRecording:(KBVoiceToTextManager *)manager {
|
- (void)voiceToTextManagerDidCancelRecording:(KBVoiceToTextManager *)manager {
|
||||||
|
self.isVoiceRecording = NO;
|
||||||
|
self.isVoiceProcessing = NO;
|
||||||
|
[self updateCollectionViewScrollState];
|
||||||
[self.voiceRecordManager cancelRecording];
|
[self.voiceRecordManager cancelRecording];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -871,6 +893,8 @@
|
|||||||
if (cell) {
|
if (cell) {
|
||||||
[cell updateLastUserMessage:KBLocalized(@"语音识别失败")];
|
[cell updateLastUserMessage:KBLocalized(@"语音识别失败")];
|
||||||
}
|
}
|
||||||
|
strongSelf.isVoiceProcessing = NO;
|
||||||
|
[strongSelf updateCollectionViewScrollState];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -881,6 +905,8 @@
|
|||||||
if (cell) {
|
if (cell) {
|
||||||
[cell removeLoadingUserMessage];
|
[cell removeLoadingUserMessage];
|
||||||
}
|
}
|
||||||
|
strongSelf.isVoiceProcessing = NO;
|
||||||
|
[strongSelf updateCollectionViewScrollState];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -888,6 +914,7 @@
|
|||||||
[cell updateLastUserMessage:transcript];
|
[cell updateLastUserMessage:transcript];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
strongSelf.isVoiceProcessing = NO;
|
||||||
[strongSelf handleTranscribedText:transcript appendToUI:NO];
|
[strongSelf handleTranscribedText:transcript appendToUI:NO];
|
||||||
});
|
});
|
||||||
}];
|
}];
|
||||||
@@ -901,6 +928,9 @@
|
|||||||
- (void)voiceRecordManager:(KBVoiceRecordManager *)manager
|
- (void)voiceRecordManager:(KBVoiceRecordManager *)manager
|
||||||
didFailWithError:(NSError *)error {
|
didFailWithError:(NSError *)error {
|
||||||
NSLog(@"[KBAIHomeVC] 录音失败:%@", error.localizedDescription);
|
NSLog(@"[KBAIHomeVC] 录音失败:%@", error.localizedDescription);
|
||||||
|
self.isVoiceRecording = NO;
|
||||||
|
self.isVoiceProcessing = NO;
|
||||||
|
[self updateCollectionViewScrollState];
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - Private
|
#pragma mark - Private
|
||||||
@@ -931,7 +961,7 @@
|
|||||||
self.pendingAIRequestCount += 1;
|
self.pendingAIRequestCount += 1;
|
||||||
self.isWaitingForAIResponse = (self.pendingAIRequestCount > 0);
|
self.isWaitingForAIResponse = (self.pendingAIRequestCount > 0);
|
||||||
if (self.pendingAIRequestCount == 1) {
|
if (self.pendingAIRequestCount == 1) {
|
||||||
self.collectionView.scrollEnabled = NO;
|
[self updateCollectionViewScrollState];
|
||||||
NSLog(@"[KBAIHomeVC] 开始等待 AI 回复,禁止 CollectionView 滚动");
|
NSLog(@"[KBAIHomeVC] 开始等待 AI 回复,禁止 CollectionView 滚动");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -950,7 +980,7 @@
|
|||||||
}
|
}
|
||||||
strongSelf.isWaitingForAIResponse = (strongSelf.pendingAIRequestCount > 0);
|
strongSelf.isWaitingForAIResponse = (strongSelf.pendingAIRequestCount > 0);
|
||||||
if (strongSelf.pendingAIRequestCount == 0) {
|
if (strongSelf.pendingAIRequestCount == 0) {
|
||||||
strongSelf.collectionView.scrollEnabled = YES;
|
[strongSelf updateCollectionViewScrollState];
|
||||||
NSLog(@"[KBAIHomeVC] AI 回复完成,恢复 CollectionView 滚动");
|
NSLog(@"[KBAIHomeVC] AI 回复完成,恢复 CollectionView 滚动");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user