|
|
@@ -1333,15 +1333,13 @@ static const CGFloat kMediaCornerRadius = 4.0f;
|
|
|
}
|
|
|
|
|
|
- (void)layoutTextContent {
|
|
|
- CGSize textSize = [self calculateTextSize];
|
|
|
+ CGSize textSize = _messageModel.textLayoutSize;
|
|
|
|
|
|
if (_messageModel.isSender) {
|
|
|
[_textLbl mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
|
make.right.equalTo(_avatarImageView.mas_left).offset(-26);
|
|
|
make.top.mas_equalTo(_avatarImageView.mas_top).offset(28);
|
|
|
make.width.mas_equalTo(textSize.width);
|
|
|
- make.height.mas_equalTo(textSize.height);
|
|
|
- make.bottom.equalTo(self.contentView).offset(-kVerticalMargin).priorityHigh();
|
|
|
}];
|
|
|
|
|
|
if (_messageModel.quoteMessage) {
|
|
|
@@ -1357,8 +1355,6 @@ static const CGFloat kMediaCornerRadius = 4.0f;
|
|
|
make.left.equalTo(_avatarImageView.mas_right).offset(26);
|
|
|
make.top.mas_equalTo(_avatarImageView.mas_top).offset(28);
|
|
|
make.width.mas_equalTo(textSize.width);
|
|
|
- make.height.mas_equalTo(textSize.height);
|
|
|
- make.bottom.equalTo(self.contentView).offset(-kVerticalMargin).priorityHigh();
|
|
|
}];
|
|
|
|
|
|
if (_messageModel.quoteMessage) {
|
|
|
@@ -1549,22 +1545,6 @@ static const CGFloat kMediaCornerRadius = 4.0f;
|
|
|
return CGSizeMake(adjustedWidth, adjustedHeight);
|
|
|
}
|
|
|
|
|
|
-- (CGSize)calculateTextSize{
|
|
|
-
|
|
|
- NSString *text = _messageModel.content ?: @"";
|
|
|
-
|
|
|
- UILabel *label = [[UILabel alloc] init];
|
|
|
- label.font = [UIFont systemFontOfSize:18.0]; // 设置字体大小
|
|
|
- label.numberOfLines = 0; // 设置为0表示不限制行数
|
|
|
- label.text = text; // 设置文本内容
|
|
|
- label.preferredMaxLayoutWidth = kContentMaxWidth; // 设置固定宽度
|
|
|
- CGSize size = [label sizeThatFits:CGSizeMake(kContentMaxWidth, CGFLOAT_MAX)];
|
|
|
-
|
|
|
- CGSize textSize = size;
|
|
|
-// NSLog(@"文本宽度: %f, 文本高度: %f", textSize.width, textSize.height);
|
|
|
- return textSize;
|
|
|
-}
|
|
|
-
|
|
|
- (NSString *)formatTimeWithMilliseconds:(NSInteger)milliseconds{
|
|
|
NSInteger seconds = milliseconds / 1000.0;
|
|
|
|
|
|
@@ -1793,12 +1773,12 @@ static const CGFloat kMediaCornerRadius = 4.0f;
|
|
|
CGFloat contentHeight = 0;
|
|
|
CGFloat horizontalMargin = 12.0f;
|
|
|
CGFloat verticalMargin = 10.0f;
|
|
|
- CGFloat maxWidth = kContentMaxWidth - 2 * horizontalMargin;
|
|
|
+ CGFloat maxWidth = kContentMaxWidth;
|
|
|
// 计算内容高度
|
|
|
switch (message.messageType) {
|
|
|
case ChatMessageTypeText: {
|
|
|
NSString *text = message.content ?: @"";
|
|
|
- UIFont *font = [UIFont systemFontOfSize:17]; // 设置字体大小
|
|
|
+ UIFont *font = [UIFont systemFontOfSize:18]; // 设置字体大小
|
|
|
CGSize maximumSize = CGSizeMake(maxWidth, CGFLOAT_MAX); // 设置最大宽度,高度设为CGFLOAT_MAX表示不限制高度
|
|
|
|
|
|
NSDictionary *attributes = @{NSFontAttributeName: font};
|
|
|
@@ -1806,7 +1786,7 @@ static const CGFloat kMediaCornerRadius = 4.0f;
|
|
|
options:NSStringDrawingUsesLineFragmentOrigin
|
|
|
attributes:attributes
|
|
|
context:nil];
|
|
|
-
|
|
|
+ message.textLayoutSize = rect.size;
|
|
|
CGFloat height = rect.size.height;
|
|
|
|
|
|
contentHeight = height + 2 * verticalMargin;
|
|
|
@@ -1849,6 +1829,8 @@ static const CGFloat kMediaCornerRadius = 4.0f;
|
|
|
case ChatMessageTypeDel:
|
|
|
contentHeight = 20.f;
|
|
|
break;
|
|
|
+ case ChatMessageTypeDFBUSY:
|
|
|
+ break;
|
|
|
}
|
|
|
|
|
|
// 总高度 = 内容高度 + 上下边距
|
|
|
@@ -1860,15 +1842,6 @@ static const CGFloat kMediaCornerRadius = 4.0f;
|
|
|
return height;
|
|
|
}
|
|
|
|
|
|
-+ (void)precalculateHeightForMessage:(ChatMessageModel *)message completion:(void(^)(CGFloat height))completion {
|
|
|
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
|
|
- CGFloat height = [self cellHeightForMessage:message];
|
|
|
- dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
- if (completion) completion(height);
|
|
|
- });
|
|
|
- });
|
|
|
-}
|
|
|
-
|
|
|
|
|
|
|
|
|
@end
|