处理滚动底部问题

This commit is contained in:
2026-01-29 14:42:49 +08:00
parent 25fbe9b64e
commit 32ebc6fb65
12 changed files with 174 additions and 26 deletions

View File

@@ -647,6 +647,12 @@
unsigned long long fileSize = [attributes[NSFileSize] unsignedLongLongValue];
NSLog(@"[KBAIHomeVC] 录音完成,时长: %.2fs,大小: %llu bytes", duration, fileSize);
// loading
KBPersonaChatCell *currentCell = [self currentPersonaCell];
if (currentCell) {
[currentCell appendLoadingUserMessage];
}
__weak typeof(self) weakSelf = self;
[self.aiVM transcribeAudioFileAtURL:fileURL
completion:^(KBAiSpeechTranscribeResponse * _Nullable response, NSError * _Nullable error) {
@@ -656,9 +662,14 @@
}
dispatch_async(dispatch_get_main_queue(), ^{
KBPersonaChatCell *cell = [strongSelf currentPersonaCell];
if (error) {
NSLog(@"[KBAIHomeVC] 语音转文字失败:%@", error.localizedDescription);
[KBHUD showError:KBLocalized(@"语音转文字失败,请重试")];
if (cell) {
[cell updateLastUserMessage:KBLocalized(@"语音识别失败")];
}
return;
}
@@ -666,10 +677,19 @@
if (transcript.length == 0) {
NSLog(@"[KBAIHomeVC] 语音转文字结果为空");
[KBHUD showError:KBLocalized(@"未识别到语音内容")];
if (cell) {
[cell updateLastUserMessage:KBLocalized(@"未识别到语音")];
}
return;
}
[strongSelf handleTranscribedText:transcript];
// loading
if (cell) {
[cell updateLastUserMessage:transcript];
}
//
[strongSelf handleTranscribedText:transcript appendToUI:NO];
});
}];
}
@@ -687,6 +707,10 @@
#pragma mark - Private
- (void)handleTranscribedText:(NSString *)text {
[self handleTranscribedText:text appendToUI:YES];
}
- (void)handleTranscribedText:(NSString *)text appendToUI:(BOOL)appendToUI {
if (text.length == 0) {
return;
}
@@ -699,7 +723,7 @@
}
KBPersonaChatCell *currentCell = [self currentPersonaCell];
if (currentCell) {
if (currentCell && appendToUI) {
[currentCell appendUserMessage:text];
}
@@ -722,6 +746,12 @@
strongSelf.isWaitingForAIResponse = NO;
strongSelf.collectionView.scrollEnabled = YES;
NSLog(@"[KBAIHomeVC] AI 回复完成,恢复 CollectionView 滚动");
// loading
KBPersonaChatCell *cell = [strongSelf currentPersonaCell];
if (cell) {
[cell markLastUserMessageLoadingComplete];
}
if (response.code == 50030) {
NSString *message = response.message ?: @"";
@@ -745,7 +775,6 @@
return;
}
KBPersonaChatCell *cell = [strongSelf currentPersonaCell];
if (cell) {
[cell appendAssistantMessage:aiResponse audioId:audioId];
}