temp save: 更好的效果

This commit is contained in:
edwinQQQ
2024-11-29 21:50:24 +08:00
parent 6b2dbee88c
commit c77bb17b03
4 changed files with 142 additions and 72 deletions

View File

@@ -38,17 +38,18 @@
self.textLayout = [YYTextLayout layoutWithContainer:container text:content];
CGSize textSize = self.textLayout.textBoundingRect.size;
// CGFloat anotherHeight = [self heightForAttributedStringUsingTextKit:content maxWidth:kRoomMessageMaxWidth];
self.rowHeight = ceil(textSize.height) + self.contentTopMargin + self.contentBottomMargin + self.cellBottomMargin + 20;
if (![NSString isEmpty:self.bubbleImageUrl]) {
self.rowHeight += 30;
} else {
self.rowHeight += 10;
}
// CGFloat anotherHeight = [self heightForAttributedStringUsingTextKit:content maxWidth:kRoomMessageMaxWidth].height;
if ([self.cellKey isEqualToString:@"ChatMessage"]) {
NSLog(@" ----- 11 ----- %@ : %@", [NSValue valueWithCGSize:textSize], [NSValue valueWithCGSize:[self heightForAttributedStringUsingTextKit:content maxWidth:kRoomMessageMaxWidth]]);
if ([NSString isEmpty:self.bubbleImageUrl]) {
self.rowHeight = ceil(textSize.height) + self.cellBottomMargin + self.contentTopMargin + 20;
} else {
self.rowHeight = ceil(textSize.height) + self.contentTopMargin + self.contentBottomMargin + self.cellBottomMargin + 20;
}
self.rowHeight += 10;
// if ([self.cellKey isEqualToString:@"ChatMessage"]) {
// NSLog(@" ----- 11 ----- %@ : %@", [NSValue valueWithCGSize:textSize], [NSValue valueWithCGSize:[self heightForAttributedStringUsingTextKit:content maxWidth:kRoomMessageMaxWidth]]);
// }
// self.rowHeight = [self heightForAttributedText:content
// maxWidth:kRoomMessageMaxWidth];

View File

@@ -14,9 +14,9 @@
- (void)setAttributedText:(NSAttributedString *)attributedText {
NSMutableAttributedString* attributedTextCopy = [attributedText mutableCopy];
CGSize maxSize = CGSizeMake(kRoomMessageMaxWidth - 24, MAXFLOAT);
self.maxWidth = maxSize.width - 8;
CGSize maxSize = CGSizeMake(kRoomMessageMaxWidth, MAXFLOAT);
self.maxWidth = maxSize.width;
CGSize size = [attributedText boundingRectWithSize:maxSize
options:NSStringDrawingUsesFontLeading | NSStringDrawingUsesLineFragmentOrigin
@@ -50,7 +50,7 @@
}
}
self.textWidth = layout.textBoundingRect.size.width;
self.textWidth = layout.textBoundingRect.size.width + 12;
[super setAttributedText:attributedTextCopy];
}
@@ -65,8 +65,8 @@
size = CGSizeMake(imageView.bounds.size.height * scale, imageView.bounds.size.height);
imageView.bounds = CGRectMake(0, 0, size.width, size.height);
}else{
size = CGSizeMake(16, 16);
imageView.bounds = CGRectMake(0, 0, 16, 16);
size = CGSizeMake(18, 18);
imageView.bounds = CGRectMake(0, 0, 18, 18);
}
NSMutableAttributedString * replaceAttr = [NSMutableAttributedString yy_attachmentStringWithContent:imageView
contentMode:UIViewContentModeScaleAspectFit

View File

@@ -27,6 +27,8 @@
@property (nonatomic,strong) XPNetImageYYLabel *contentLabel;
///
@property (nonatomic,strong) UITapGestureRecognizer *tapEmptyRecognizer;
@property(nonatomic, strong) UIVisualEffectView *blurEffectView;
@end
@implementation XPRoomMessageTableViewCell
@@ -45,8 +47,9 @@
self.contentView.clipsToBounds = NO;
self.selectionStyle = UITableViewCellSelectionStyleNone;
self.backgroundColor = [UIColor colorWithRed:arc4random()%255/255.0 green:arc4random()%255/255.0 blue:arc4random()%255/255.0 alpha:0.4];//[UIColor clearColor];
self.backgroundColor = [UIColor clearColor];
[self.contentView addSubview:self.bubbleImageView];
[self.contentView addSubview:self.blurEffectView];
[self.contentView addSubview:self.contentLabel];
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTap)];
tap.delegate = self;
@@ -59,9 +62,9 @@
- (void)initSubViewConstraints {
[self.bubbleImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.mas_equalTo(self.contentLabel).offset(-20);
make.top.mas_equalTo(self.contentLabel).offset(-10);
make.bottom.mas_equalTo(self.contentLabel);//.offset(10);
make.leading.mas_equalTo(self.contentLabel).offset(-16);
make.top.mas_equalTo(self.contentLabel).offset(0);
make.bottom.mas_equalTo(self.contentLabel).offset(10);
make.trailing.mas_equalTo(self.contentLabel).offset(20);
}];
@@ -70,6 +73,10 @@
make.bottom.mas_equalTo(-20);
make.top.mas_equalTo(10);
}];
[self.blurEffectView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.bubbleImageView);
}];
}
- (void)setIsLeftBigImage:(BOOL)isLeftBigImage {
@@ -144,34 +151,59 @@
self.contentLabel.attributedText = messageInfo.content;
// self.contentLabel.textLayout = messageInfo.textLayout;
if (messageInfo.bubbleImageUrl.length) {
if (![NSString isEmpty:messageInfo.bubbleImageUrl]) {
self.blurEffectView.hidden = YES;
@kWeakify(self);
[self.bubbleImageView loadImageWithUrl:messageInfo.bubbleImageUrl completion:^(UIImage * _Nonnull image, NSURL * _Nonnull url) {
@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.contentLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
make.leading.mas_equalTo(messageInfo.contentLeftMargin);
make.top.mas_equalTo(messageInfo.contentTopMargin);
make.bottom.mas_equalTo(- messageInfo.contentBottomMargin - messageInfo.cellBottomMargin);
// make.centerY.mas_equalTo(self.contentView);
// if (isMSRTL()) {
make.width.mas_greaterThanOrEqualTo([self RTLLabelWidth] - messageInfo.contentLeftMargin);
// make.height.mas_greaterThanOrEqualTo([self RTLLabelHeight]);
// }
}];
[self.bubbleImageView mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(0);
make.leading.trailing.mas_equalTo(self.contentView).offset(0);
// make.trailing.mas_equalTo(self.contentLabel).offset(-messageInfo.contentRightMargin - 10);
}];
}];
[self.contentLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
make.leading.mas_equalTo(self.bubbleImageView).offset(self.messageInfo.contentLeftMargin + 12);
// make.top.mas_equalTo(self.bubbleImageView).offset(self.messageInfo.contentTopMargin+20);
// make.bottom.mas_equalTo(self.bubbleImageView).offset(-self.messageInfo.contentBottomMargin-10);
make.top.mas_equalTo(-10);
make.bottom.mas_equalTo(0);
if (isMSRTL()) { // MARK: 使 layout
make.width.mas_greaterThanOrEqualTo([self RTLLabelWidth]);
}
}];
} else {
self.blurEffectView.hidden = NO;
self.bubbleImageView.image = [UIImage imageWithColor:[DJDKMIMOMColor messageBubbleColor]];
[self.contentLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.contentView).inset(10);
// make.leading.mas_equalTo(self.bubbleImageView).offset(self.messageInfo.contentLeftMargin + 12);
// make.top.mas_equalTo(self.bubbleImageView).offset(self.messageInfo.contentTopMargin+10);
// make.bottom.mas_equalTo(self.bubbleImageView).offset(-self.messageInfo.contentBottomMargin-20);
// if (isMSRTL()) { // MARK: 使 layout
// make.width.mas_greaterThanOrEqualTo([self RTLLabelWidth]);
// }
make.leading.mas_equalTo(messageInfo.contentLeftMargin);
make.bottom.mas_equalTo(-messageInfo.cellBottomMargin);
make.top.mas_equalTo(messageInfo.contentTopMargin);
make.width.mas_equalTo([self RTLLabelWidth] - messageInfo.contentLeftMargin);
}];
// [self.contentLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
//// make.top.equalTo(self.contentView).offset(10); // 10
//// make.bottom.equalTo(self.contentView).offset(-10); // 10
//// make.trailing.equalTo(self.contentView).offset(-10); // 10
//// make.centerY.mas_equalTo(self.contentView);
//// if (isMSRTL()) {
//// make.width.mas_greaterThanOrEqualTo([self RTLLabelWidth]);
// make.height.mas_greaterThanOrEqualTo([self RTLLabelHeight]);
//// }
// make.leading.equalTo(self.contentView).offset(10); //
// }];
[self.bubbleImageView mas_updateConstraints:^(MASConstraintMaker *make) {
make.leading.mas_equalTo(self.contentLabel).offset(-8);
make.trailing.mas_equalTo(self.contentLabel).offset(8);
make.bottom.mas_equalTo(self.contentLabel).offset(0);
}];
}
@@ -200,8 +232,16 @@
CGSize size = [self.contentLabel.attributedText boundingRectWithSize:CGSizeMake(kRoomMessageMaxWidth, 0)
options:NSStringDrawingUsesFontLeading | NSStringDrawingUsesLineFragmentOrigin
context:nil].size;
NSLog(@" ----- 11 ----- %@", [NSValue valueWithCGSize:size]);
return MIN(ceil(size.width) + self.messageInfo.contentLeftMargin + self.messageInfo.contentRightMargin + 8, self.contentLabel.maxWidth);
// NSLog(@" ----- 11 ----- %@", [NSValue valueWithCGSize:size]);
// return MIN(ceil(size.width) + self.messageInfo.contentLeftMargin + self.messageInfo.contentRightMargin + 8, self.contentLabel.maxWidth);
return ceil(size.width);// + self.messageInfo.contentLeftMargin + self.messageInfo.contentRightMargin + 8;
}
- (CGFloat)RTLLabelHeight {
CGSize size = [self.contentLabel.attributedText boundingRectWithSize:CGSizeMake(kRoomMessageMaxWidth, 0)
options:NSStringDrawingUsesFontLeading | NSStringDrawingUsesLineFragmentOrigin
context:nil].size;
return ceil(size.height);
}
- (UIImage *)scaleToSize:(UIImage *)img {
@@ -232,14 +272,19 @@
}
}
- (NetImageView *)bubbleImageView {
if (!_bubbleImageView) {
_bubbleImageView = [[NetImageView alloc] init];
_bubbleImageView.clipsToBounds = NO;
_bubbleImageView.userInteractionEnabled = YES;
_bubbleImageView.layer.masksToBounds = YES;
_bubbleImageView.layer.cornerRadius = 7;
[_bubbleImageView setCornerRadius:8];
// _bubbleImageView.layer.masksToBounds = YES;
// _bubbleImageView.layer.cornerRadius = 8;
// [_contentLabel setCornerRadius:8
// corners:kCALayerMinXMinYCorner | kCALayerMaxXMinYCorner | kCALayerMaxXMaxYCorner | kCALayerMinXMaxYCorner
// borderWidth:1
// borderColor:[UIColor greenColor]];
}
return _bubbleImageView;
}
@@ -256,9 +301,15 @@
- (XPNetImageYYLabel *)contentLabel {
if (!_contentLabel) {
_contentLabel = [[XPNetImageYYLabel alloc] init];
_contentLabel.preferredMaxLayoutWidth = kRoomMessageMaxWidth - 24;
_contentLabel.preferredMaxLayoutWidth = kRoomMessageMaxWidth ;
_contentLabel.numberOfLines = 0;
_contentLabel.userInteractionEnabled = YES;
// [_contentLabel setCornerRadius:8
// corners:kCALayerMinXMinYCorner | kCALayerMaxXMinYCorner | kCALayerMaxXMaxYCorner | kCALayerMinXMaxYCorner
// borderWidth:1
// borderColor:[UIColor redColor]];
}
return _contentLabel;
}
@@ -270,4 +321,22 @@
}
return _clickBtn;
}
- (UIVisualEffectView *)blurEffectView {
if (!_blurEffectView) {
//
UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]; // Light, Dark, ExtraLight
//
_blurEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
//
_blurEffectView.frame = CGRectMake(0, 0, KScreenWidth, 200);
_blurEffectView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; // 使
_blurEffectView.hidden = YES;
[_blurEffectView setCornerRadius:8];
}
return _blurEffectView;
}
@end

View File

@@ -1118,35 +1118,35 @@ NSString * const kRoomShowTopicKey = @"kRoomShowTopicKey";
#pragma mark - UITableViewDelegate And UITableViewDataSource
//- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
// NSArray *source = @[];
// switch (self.displayType) {
// case 1:
// source = self.datasource;
// break;
// case 2:
// source = self.datasource_chat;
// break;
// case 3:
// source = self.datasource_gift;
// break;
//
// default:
// source = self.datasource;
// break;
// }
//
// XPMessageInfoModel *model = [source xpSafeObjectAtIndex:indexPath.row];
//
// // model 使 model
// if (model.rowHeight > 0) {
// return model.rowHeight;
// }
//
// // 使
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
NSArray *source = @[];
switch (self.displayType) {
case 1:
source = self.datasource;
break;
case 2:
source = self.datasource_chat;
break;
case 3:
source = self.datasource_gift;
break;
default:
source = self.datasource;
break;
}
XPMessageInfoModel *model = [source xpSafeObjectAtIndex:indexPath.row];
// model 使 model
if (model.rowHeight > 0) {
return model.rowHeight;
}
// 使
// return 100;
//// return UITableViewAutomaticDimension;
//}
return UITableViewAutomaticDimension;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
switch (self.displayType) {
@@ -1336,7 +1336,7 @@ NSString * const kRoomShowTopicKey = @"kRoomShowTopicKey";
_messageTableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
_messageTableView.delegate = self;
_messageTableView.dataSource = self;
// _messageTableView.rowHeight = UITableViewAutomaticDimension;
_messageTableView.rowHeight = UITableViewAutomaticDimension;
// _messageTableView.estimatedRowHeight = 44; //
_messageTableView.tableFooterView = [UIView new];
_messageTableView.separatorStyle = UITableViewCellSeparatorStyleNone;