修改bug

This commit is contained in:
2026-01-27 17:03:16 +08:00
parent 2b749cd2b0
commit e67bc37571
4 changed files with 134 additions and 35 deletions

View File

@@ -65,6 +65,9 @@
/// AiVM
@property (nonatomic, strong) AiVM *aiVM;
/// AI
@property (nonatomic, assign) BOOL isWaitingForAIResponse;
@end
@implementation KBAIHomeVC
@@ -83,6 +86,7 @@
self.currentIndex = 0;
self.preloadedIndexes = [NSMutableSet set];
self.aiVM = [[AiVM alloc] init];
self.isWaitingForAIResponse = NO; //
[self setupUI];
[self setupVoiceToTextManager];
@@ -259,6 +263,11 @@
#pragma mark - UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
// AI
if (self.isWaitingForAIResponse) {
return;
}
CGFloat pageHeight = scrollView.bounds.size.height;
CGFloat offsetY = scrollView.contentOffset.y;
NSInteger currentPage = offsetY / pageHeight;
@@ -288,6 +297,16 @@
[self updateChatViewBottomInset];
}
/// AI
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
if (self.isWaitingForAIResponse) {
NSLog(@"[KBAIHomeVC] 正在等待 AI 回复,禁止滚动");
//
scrollView.scrollEnabled = NO;
scrollView.scrollEnabled = YES;
}
}
#pragma mark - 4
- (void)setupVoiceToTextManager {
@@ -607,6 +626,11 @@
[currentCell appendUserMessage:text];
}
// CollectionView
self.isWaitingForAIResponse = YES;
self.collectionView.scrollEnabled = NO;
NSLog(@"[KBAIHomeVC] 开始等待 AI 回复,禁止 CollectionView 滚动");
__weak typeof(self) weakSelf = self;
[self.aiVM requestChatMessageWithContent:text
companionId:companionId
@@ -617,10 +641,10 @@
}
dispatch_async(dispatch_get_main_queue(), ^{
// if (error) {
// NSLog(@"[KBAIHomeVC] 请求聊天失败:%@", error.localizedDescription);
// return;
// }
// CollectionView
strongSelf.isWaitingForAIResponse = NO;
strongSelf.collectionView.scrollEnabled = YES;
NSLog(@"[KBAIHomeVC] AI 回复完成,恢复 CollectionView 滚动");
if (response.code == 50030) {
NSString *message = response.message ?: @"";