修改bug
This commit is contained in:
@@ -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 ?: @"";
|
||||
|
||||
Reference in New Issue
Block a user