处理语音
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
@property (nonatomic, strong) UIView *bubbleView;
|
||||
@property (nonatomic, strong, readwrite) UILabel *messageLabel; // readwrite 允许内部修改
|
||||
@property (nonatomic, strong) UIActivityIndicatorView *loadingIndicator;
|
||||
@property (nonatomic, strong) UIActivityIndicatorView *messageLoadingIndicator; // AI 消息加载指示器
|
||||
@property (nonatomic, strong) KBAiChatMessage *currentMessage;
|
||||
|
||||
// 打字机效果
|
||||
@@ -61,6 +62,12 @@
|
||||
self.loadingIndicator.hidesWhenStopped = YES;
|
||||
[self.contentView addSubview:self.loadingIndicator];
|
||||
|
||||
// AI 消息加载指示器(用于等待 AI 回复)
|
||||
self.messageLoadingIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleMedium];
|
||||
self.messageLoadingIndicator.color = [UIColor whiteColor];
|
||||
self.messageLoadingIndicator.hidesWhenStopped = YES;
|
||||
[self.contentView addSubview:self.messageLoadingIndicator];
|
||||
|
||||
// 气泡视图
|
||||
self.bubbleView = [[UIView alloc] init];
|
||||
self.bubbleView.backgroundColor = [UIColor colorWithRed:0.2 green:0.2 blue:0.2 alpha:0.7];
|
||||
@@ -83,8 +90,7 @@
|
||||
[self.voiceButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.equalTo(self.contentView).offset(16);
|
||||
make.top.equalTo(self.contentView).offset(8);
|
||||
// make.width.height.mas_equalTo(24);
|
||||
make.width.height.mas_equalTo(0);
|
||||
make.width.height.mas_equalTo(24);
|
||||
}];
|
||||
|
||||
[self.durationLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
@@ -96,6 +102,12 @@
|
||||
make.center.equalTo(self.voiceButton);
|
||||
}];
|
||||
|
||||
// AI 消息加载指示器约束(与 bubbleView 位置一致)
|
||||
[self.messageLoadingIndicator mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.equalTo(self.contentView).offset(16);
|
||||
make.top.equalTo(self.voiceButton.mas_bottom).offset(12);
|
||||
}];
|
||||
|
||||
// 关键修复:bubbleView 必须有明确的高度约束链
|
||||
[self.bubbleView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.equalTo(self.voiceButton.mas_bottom).offset(4);
|
||||
@@ -116,8 +128,8 @@
|
||||
}
|
||||
|
||||
- (void)configureWithMessage:(KBAiChatMessage *)message {
|
||||
NSLog(@"[KBChatAssistantMessageCell] 配置消息 - 文本长度: %lu, isComplete: %d, needsTypewriter: %d, 打字机运行中: %d",
|
||||
(unsigned long)message.text.length, message.isComplete, message.needsTypewriterEffect,
|
||||
NSLog(@"[KBChatAssistantMessageCell] 配置消息 - 文本长度: %lu, isComplete: %d, needsTypewriter: %d, isLoading: %d, 打字机运行中: %d",
|
||||
(unsigned long)message.text.length, message.isComplete, message.needsTypewriterEffect, message.isLoading,
|
||||
(self.typewriterTimer && self.typewriterTimer.isValid));
|
||||
|
||||
// 先停止之前的打字机效果(无论是否是同一条消息)
|
||||
@@ -125,6 +137,21 @@
|
||||
|
||||
self.currentMessage = message;
|
||||
|
||||
// 处理 loading 状态
|
||||
if (message.isLoading) {
|
||||
self.messageLabel.attributedText = nil;
|
||||
self.messageLabel.text = @"";
|
||||
self.bubbleView.hidden = YES;
|
||||
self.voiceButton.hidden = YES;
|
||||
self.durationLabel.hidden = YES;
|
||||
[self.messageLoadingIndicator startAnimating];
|
||||
return;
|
||||
}
|
||||
|
||||
// 非 loading 状态,隐藏 loading 指示器,显示气泡
|
||||
[self.messageLoadingIndicator stopAnimating];
|
||||
self.bubbleView.hidden = NO;
|
||||
|
||||
// 只有明确需要打字机效果的消息才使用打字机
|
||||
if (message.needsTypewriterEffect && !message.isComplete && message.text.length > 0) {
|
||||
// 启动新的打字机效果
|
||||
|
||||
Reference in New Issue
Block a user