修改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

@@ -73,6 +73,7 @@
self.messageLabel.numberOfLines = 0;
self.messageLabel.font = [UIFont systemFontOfSize:16];
self.messageLabel.textColor = [UIColor whiteColor];
self.messageLabel.lineBreakMode = NSLineBreakByWordWrapping;
// preferredMaxLayoutWidth AutoLayout
CGFloat maxWidth = [UIScreen mainScreen].bounds.size.width * 0.75 - 16 - 24;
self.messageLabel.preferredMaxLayoutWidth = maxWidth;
@@ -94,20 +95,22 @@
make.center.equalTo(self.voiceButton);
}];
// bubbleView
// bubbleView
[self.bubbleView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.voiceButton.mas_bottom).offset(4);
make.bottom.equalTo(self.contentView).offset(-4);
make.bottom.equalTo(self.contentView).offset(-4).priority(999); //
make.left.equalTo(self.contentView).offset(16);
make.width.lessThanOrEqualTo(self.contentView).multipliedBy(0.75);
}];
// messageLabel
// messageLabel AutoLayout bubbleView
[self.messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.bubbleView).offset(10);
make.bottom.equalTo(self.bubbleView).offset(-10);
make.bottom.equalTo(self.bubbleView).offset(-10).priority(999); //
make.left.equalTo(self.bubbleView).offset(12);
make.right.equalTo(self.bubbleView).offset(-12);
// messageLabel 0
make.height.greaterThanOrEqualTo(@20);
}];
}
@@ -127,10 +130,18 @@
NSLog(@"[KBChatAssistantMessageCell] 启动新的打字机效果");
[self startTypewriterEffectWithText:message.text];
} else {
//
// attributedText使 text
NSLog(@"[KBChatAssistantMessageCell] 直接显示完整文本needsTypewriter: %d, isComplete: %d",
message.needsTypewriterEffect, message.isComplete);
self.messageLabel.text = message.text;
self.messageLabel.attributedText = nil; // attributedText
self.messageLabel.text = message.text; //
//
[self.contentView setNeedsLayout];
[self.contentView layoutIfNeeded];
NSLog(@"[KBChatAssistantMessageCell] 直接显示后 Label frame: %@",
NSStringFromCGRect(self.messageLabel.frame));
}
// 0
@@ -191,30 +202,33 @@
self.fullText = text;
self.currentCharIndex = 0;
//
//
self.messageLabel.text = text;
//
[self.messageLabel setNeedsLayout];
[self.bubbleView setNeedsLayout];
// Cell
[self.contentView setNeedsLayout];
[self layoutIfNeeded];
[self.contentView layoutIfNeeded];
NSLog(@"[KBChatAssistantMessageCell] 布局后 Label frame: %@", NSStringFromCGRect(self.messageLabel.frame));
NSLog(@"[KBChatAssistantMessageCell] 布局后 Label frame: %@, bubbleView frame: %@",
NSStringFromCGRect(self.messageLabel.frame),
NSStringFromCGRect(self.bubbleView.frame));
// 使 NSAttributedString
//
NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithString:text];
[attributedText addAttribute:NSForegroundColorAttributeName
value:[UIColor clearColor]
range:NSMakeRange(0, text.length)];
[attributedText addAttribute:NSFontAttributeName
value:self.messageLabel.font
range:NSMakeRange(0, text.length)];
self.messageLabel.attributedText = attributedText;
// 线
// attributedText
dispatch_async(dispatch_get_main_queue(), ^{
// 使 NSAttributedString
//
NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithString:text];
[attributedText addAttribute:NSForegroundColorAttributeName
value:[UIColor clearColor]
range:NSMakeRange(0, text.length)];
[attributedText addAttribute:NSFontAttributeName
value:self.messageLabel.font
range:NSMakeRange(0, text.length)];
self.messageLabel.attributedText = attributedText;
// attributedText
[self.contentView layoutIfNeeded];
// 0.03
self.typewriterTimer = [NSTimer scheduledTimerWithTimeInterval:0.03
target:self