更新 .vscode/settings.json 文件,新增拼写检查词汇 "Defalut" 和 "MAXFLOAT";在 XPRoomSendTextView.m 中调整约束逻辑,确保 editTextFiled 和 imageButton 的布局正确;在 XPRoomMessageTableViewCell.m 中优化消息内容标签的约束,确保气泡和内容标签的布局一致性,增强代码可读性和健壮性。
This commit is contained in:
@@ -362,16 +362,17 @@
|
||||
make.trailing.equalTo(self.sendButton.mas_leading).mas_offset(-8);
|
||||
|
||||
}];
|
||||
[self.editTextFiled mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.leading.mas_equalTo(20);
|
||||
make.trailing.mas_equalTo(-kGetScaleWidth(20));
|
||||
make.top.bottom.mas_equalTo(0);
|
||||
}];
|
||||
|
||||
[self.imageButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.centerY.mas_equalTo(self.editTextFiled);
|
||||
make.centerY.mas_equalTo(self.bgEditTextFiled);
|
||||
make.size.mas_equalTo(CGSizeMake(26, 26));
|
||||
make.trailing.mas_equalTo(self.editTextFiled);//.offset(-10);
|
||||
make.trailing.mas_equalTo(self.bgEditTextFiled).offset(-10);
|
||||
}];
|
||||
|
||||
[self.editTextFiled mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.leading.mas_equalTo(20);
|
||||
make.trailing.mas_equalTo(self.imageButton.mas_leading).offset(-8);
|
||||
make.top.bottom.mas_equalTo(0);
|
||||
}];
|
||||
|
||||
[self.sendButton mas_remakeConstraints:^(MASConstraintMaker *make) {
|
||||
|
@@ -138,6 +138,7 @@
|
||||
}
|
||||
_messageInfo = messageInfo;
|
||||
if (messageInfo) {
|
||||
// 确保在设置attributedText之前先设置hasBubble属性
|
||||
self.contentLabel.hasBubble = ![NSString isEmpty:messageInfo.bubbleImageUrl];
|
||||
self.contentLabel.attributedText = messageInfo.content;
|
||||
|
||||
@@ -162,13 +163,20 @@
|
||||
if (self.isLeftBigImage) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 使用与XPNetImageYYLabel中一致的边距计算
|
||||
CGFloat leftMargin = hasBubble ? 16 : 12;
|
||||
|
||||
[self.contentLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.mas_equalTo(self.messageInfo.contentTopMargin);
|
||||
make.bottom.mas_equalTo(-self.messageInfo.cellBottomMargin);
|
||||
make.leading.mas_equalTo(self.messageInfo.contentLeftMargin);
|
||||
make.width.mas_lessThanOrEqualTo(size.width).priority(UILayoutPriorityDefaultHigh); // 优先使用宽度限制
|
||||
// 设置右间距
|
||||
make.trailing.mas_lessThanOrEqualTo(self.contentView).offset(-self.messageInfo.contentLeftMargin).priority(UILayoutPriorityRequired); // 当宽度到达边缘时,使用右间距
|
||||
make.leading.mas_equalTo(leftMargin);
|
||||
|
||||
// 使用trailing约束限制最大宽度,确保不超出父容器边界
|
||||
make.trailing.mas_lessThanOrEqualTo(self.contentView).offset(-leftMargin).priority(UILayoutPriorityRequired);
|
||||
|
||||
// 设置首选宽度,但允许被trailing约束压缩
|
||||
make.width.mas_lessThanOrEqualTo(size.width).priority(UILayoutPriorityDefaultHigh);
|
||||
}];
|
||||
|
||||
if (hasBubble) {
|
||||
@@ -178,18 +186,24 @@
|
||||
@kStrongify(self);
|
||||
UIImage *image1 = [UIImage imageWithCGImage:image.CGImage scale:2.0 orientation:UIImageOrientationUp];
|
||||
UIImage *cutImage = [image1 cropRightAndBottomPixels:2];
|
||||
self.bubbleImageView.image = [self resizableImage:cutImage];
|
||||
self.bubbleImageView.image = [self resizableImage:cutImage];
|
||||
|
||||
// 确保气泡约束不会影响contentLabel的尺寸
|
||||
[self.bubbleImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.bottom.mas_equalTo(self.contentLabel).inset(-4);
|
||||
make.leading.trailing.mas_equalTo(self.contentLabel).inset(-16);
|
||||
}];
|
||||
|
||||
// 强制更新布局
|
||||
[self.contentView setNeedsLayout];
|
||||
[self.contentView layoutIfNeeded];
|
||||
}];
|
||||
} else {
|
||||
self.bubbleImageView.image = [UIImage imageWithColor:[DJDKMIMOMColor messageBubbleColor]];
|
||||
[self.bubbleImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.bottom.mas_equalTo(self.contentLabel);
|
||||
make.leading.mas_equalTo(self.contentLabel).offset(-self.messageInfo.contentLeftMargin);
|
||||
make.trailing.mas_equalTo(self.contentLabel).offset(self.messageInfo.contentLeftMargin);
|
||||
make.leading.mas_equalTo(self.contentLabel).offset(-leftMargin);
|
||||
make.trailing.mas_equalTo(self.contentLabel).offset(leftMargin);
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user