From 6b2dbee88c0c883e63e30166423a7d4813164333 Mon Sep 17 00:00:00 2001 From: edwinQQQ <> Date: Fri, 29 Nov 2024 16:46:36 +0800 Subject: [PATCH] =?UTF-8?q?temp=20save:=20=E5=9F=BA=E6=9C=AC=E5=AE=8C?= =?UTF-8?q?=E6=95=B4=E6=98=BE=E7=A4=BA=E8=81=8A=E5=A4=A9=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Model/XPMessageInfoModel.h | 3 + .../Model/XPMessageInfoModel.m | 30 +- .../Tool/XPRoomMessageConstant.h | 2 +- .../Tool/XPRoomMessageParser.m | 140 ++++----- .../View/XPNetImageYYLabel.m | 6 +- .../View/XPRoomMessageTableViewCell.m | 100 +++--- .../XPRoomMessageContainerView.m | 289 ++++++++++-------- YuMi/Modules/YMRoom/View/ThemeColor+Room.m | 3 +- 8 files changed, 325 insertions(+), 248 deletions(-) diff --git a/YuMi/Modules/YMRoom/View/MessageContainerView/Model/XPMessageInfoModel.h b/YuMi/Modules/YMRoom/View/MessageContainerView/Model/XPMessageInfoModel.h index fc278c97..f16481e2 100644 --- a/YuMi/Modules/YMRoom/View/MessageContainerView/Model/XPMessageInfoModel.h +++ b/YuMi/Modules/YMRoom/View/MessageContainerView/Model/XPMessageInfoModel.h @@ -23,6 +23,7 @@ NS_ASSUME_NONNULL_BEGIN ///cell的高度 @property (nonatomic,assign) CGFloat rowHeight; @property (nonatomic,assign) CGFloat textWidth; +@property(nonatomic, strong) YYTextLayout *textLayout; @property(nonatomic, strong) NSMutableArray *extraSizeArray; ///文本内容的 @property (nonatomic,assign) CGFloat contentLeftMargin; @@ -43,6 +44,8 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, copy) NSString *boomImageUrl; +@property(nonatomic, copy) NSString *cellKey; + @end NS_ASSUME_NONNULL_END diff --git a/YuMi/Modules/YMRoom/View/MessageContainerView/Model/XPMessageInfoModel.m b/YuMi/Modules/YMRoom/View/MessageContainerView/Model/XPMessageInfoModel.m index df078949..a28a1e15 100644 --- a/YuMi/Modules/YMRoom/View/MessageContainerView/Model/XPMessageInfoModel.m +++ b/YuMi/Modules/YMRoom/View/MessageContainerView/Model/XPMessageInfoModel.m @@ -28,8 +28,30 @@ - (void)setContent:(NSAttributedString *)content { _content = content; - self.rowHeight = [self heightForAttributedText:content - maxWidth:kRoomMessageMaxWidth]; + CGSize size = [content boundingRectWithSize:CGSizeMake(kRoomMessageMaxWidth, 0) + options:NSStringDrawingUsesFontLeading | NSStringDrawingUsesLineFragmentOrigin + context:nil].size; + + YYTextContainer *container = [YYTextContainer containerWithSize:CGSizeMake(size.width, CGFLOAT_MAX)]; + container.maximumNumberOfRows = 0; + container.truncationType = YYTextTruncationTypeEnd; + 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; + } + + if ([self.cellKey isEqualToString:@"ChatMessage"]) { + NSLog(@" ----- 11 ----- %@ : %@", [NSValue valueWithCGSize:textSize], [NSValue valueWithCGSize:[self heightForAttributedStringUsingTextKit:content maxWidth:kRoomMessageMaxWidth]]); + } + +// self.rowHeight = [self heightForAttributedText:content +// maxWidth:kRoomMessageMaxWidth]; // CGFloat width = isMSRTL() ? 10 : 0; ////// width = self.vipIcon.length > 0 ? width + 15 : width; @@ -41,7 +63,7 @@ // self.rowHeight = rowHeight + width ; } -- (CGFloat)heightForAttributedStringUsingTextKit:(NSAttributedString *)attributedString +- (CGSize)heightForAttributedStringUsingTextKit:(NSAttributedString *)attributedString maxWidth:(CGFloat)maxWidth { NSTextStorage *textStorage = [[NSTextStorage alloc] initWithAttributedString:attributedString]; NSTextContainer *textContainer = [[NSTextContainer alloc] initWithSize:CGSizeMake(maxWidth, CGFLOAT_MAX)]; @@ -52,7 +74,7 @@ // 让布局管理器计算文本高度 [layoutManager glyphRangeForTextContainer:textContainer]; - return ceil([layoutManager usedRectForTextContainer:textContainer].size.height); // 向上取整 + return [layoutManager usedRectForTextContainer:textContainer].size; } - (CGFloat)heightForAttributedText:(NSAttributedString *)attributedText maxWidth:(CGFloat)maxWidth { diff --git a/YuMi/Modules/YMRoom/View/MessageContainerView/Tool/XPRoomMessageConstant.h b/YuMi/Modules/YMRoom/View/MessageContainerView/Tool/XPRoomMessageConstant.h index 8a682b25..d7de4c41 100644 --- a/YuMi/Modules/YMRoom/View/MessageContainerView/Tool/XPRoomMessageConstant.h +++ b/YuMi/Modules/YMRoom/View/MessageContainerView/Tool/XPRoomMessageConstant.h @@ -10,7 +10,7 @@ #ifndef XPRoomMessageConstant_h #define XPRoomMessageConstant_h -#define kRoomMessageMaxWidth (KScreenWidth - 15 - 90) +#define kRoomMessageMaxWidth (KScreenWidth - 15 - 90 - 8) ///公屏文本字体的大小 static CGFloat kRoomMessageDefalutFont = 15; diff --git a/YuMi/Modules/YMRoom/View/MessageContainerView/Tool/XPRoomMessageParser.m b/YuMi/Modules/YMRoom/View/MessageContainerView/Tool/XPRoomMessageParser.m index 58f36c0d..685e9433 100644 --- a/YuMi/Modules/YMRoom/View/MessageContainerView/Tool/XPRoomMessageParser.m +++ b/YuMi/Modules/YMRoom/View/MessageContainerView/Tool/XPRoomMessageParser.m @@ -59,29 +59,6 @@ @implementation XPRoomMessageParser -- (XPMessageInfoModel*)parseMessageAttributeForChatHall:(NIMMessage *)message{ - NIMMessageType messageType = message.messageType; - XPMessageInfoModel * messageInfo = [[XPMessageInfoModel alloc] init]; - messageInfo.isChatHall = YES; - switch (messageType) { - case NIMMessageTypeText: - { - XPMessageInfoModel *model = [self makeChatAttribute:message messageInfo:messageInfo]; - return model != nil ? model : [XPMessageInfoModel new]; - break; - } - - case NIMMessageTypeCustom: - { - XPMessageInfoModel *model = [self makeCustomAttribute:message messageInfo:messageInfo]; - return model != nil ? model : [XPMessageInfoModel new]; - break; - } - default: - return [XPMessageInfoModel new]; - } -} - - (XPMessageInfoModel*)parseBroadcastMessageAttribute:(NIMBroadcastMessage *)message { if (message.content) { NSDictionary *msgDictionary = [message.content toJSONObject]; @@ -278,72 +255,56 @@ if ([self isCurrentRoomSuperAdmin:message.from]) { [attribute appendAttributedString:[self createLanguageImageAttribute:@"common_super_admin"]]; } - if (![NSString isEmpty:model.experUrl]) { + messageInfo.experUrl = model.experUrl; [attribute appendAttributedString:[self createUrlImageAttribute:model.experUrl]]; [attribute appendAttributedString:[self createSapceAttribute:2]]; } - if (![NSString isEmpty:model.charmUrl]) {//等级 + messageInfo.charmUrl = model.charmUrl; [attribute appendAttributedString:[self createUrlImageAttribute:model.charmUrl]]; [attribute appendAttributedString:[self createSapceAttribute:2]]; } - if (![NSString isEmpty:model.vipIcon]) { + messageInfo.vipIcon = model.vipIcon; [attribute appendAttributedString:[self createUrlImageAttribute:model.vipIcon]]; [attribute appendAttributedString:[self createSapceAttribute:2]]; } - if(model.isCustomWord == YES){ - if (model.inRoomNameplatePic.length > 0){ - [attribute appendAttributedString:[self createUrlImageAttribute:model.inRoomNameplatePic]]; - [attribute appendAttributedString:[self createSapceAttribute:2]]; - } - }else{ - if (model.inRoomNameplatePic.length > 0) { //铭牌有图片加文字 - [attribute appendAttributedString:[self createNameplateAttibute:model.inRoomNameplateWord image:model.inRoomNameplatePic textFont:[UIFont systemFontOfSize:9]]]; - [attribute appendAttributedString:[self createSapceAttribute:2]]; - } -// if (model.inRoomNameplatePic.length > 0 && model.inRoomNameplateWord.length > 0) { //铭牌有图片加文字 -// [attribute appendAttributedString:[self createNameplateAttibute:model.inRoomNameplateWord image:model.inRoomNameplatePic textFont:[UIFont systemFontOfSize:9]]]; -// [attribute appendAttributedString:[self createSapceAttribute:2]]; -// } else if (model.inRoomNameplatePic.length > 0) {//铭牌只有图片 -// [attribute appendAttributedString:[self createUrlImageAttribute:model.inRoomNameplatePic]]; -// [attribute appendAttributedString:[self createSapceAttribute:2]]; -// } + if (model.inRoomNameplatePic.length > 0) { + [attribute appendAttributedString:[self createUrlImageAttribute:model.inRoomNameplatePic + size:CGSizeMake(60, kFontRegular(kRoomMessageDefalutFont).lineHeight)]]; + [attribute appendAttributedString:[self createSapceAttribute:2]]; } - [attribute appendAttributedString:[self createTextAttribute:nick color:[DJDKMIMOMColor messageDefaultTextColor] font:kRoomMessageDefalutFont]]; + [attribute appendAttributedString:[self createTextAttribute:nick color:[UIColor colorWithWhite:1 alpha:0.7] font:kRoomMessageDefalutFont]]; [attribute appendAttributedString:[self createSapceAttribute:2]]; id nickNameNifo = message.remoteExt[@"atNames"]; - NSMutableAttributedString *msgStr; + if (message.text) { - if(messageInfo.isChatHall == YES){ - QEmotionHelper *faceManager = [QEmotionHelper sharedEmotionHelper]; - msgStr = [faceManager attributedStringByText:message.text font:[UIFont systemFontOfSize:kRoomMessageDefalutFont]]; - [msgStr addAttributes:@{NSForegroundColorAttributeName: [DJDKMIMOMColor messageTextColor]} range:[msgStr.string rangeOfString:msgStr.string]]; - - }else{ - msgStr = [[NSMutableAttributedString alloc] initWithString:message.text]; - [msgStr addAttribute:NSForegroundColorAttributeName - value:[DJDKMIMOMColor messageTextColor] - range:NSMakeRange(0, msgStr.length)]; - if ([nickNameNifo isKindOfClass:[NSArray class]]) { - for (NSString *nick in nickNameNifo) { - NSRange range = [message.text rangeOfString:nick]; - if (range.length) { - [msgStr yy_setTextHighlightRange:range color:UIColorFromRGB(0xFD85C9) backgroundColor:[UIColor clearColor] userInfo:nil]; - } + NSMutableAttributedString *msgStr; + msgStr = [[NSMutableAttributedString alloc] initWithString:message.text]; + [msgStr addAttribute:NSForegroundColorAttributeName + value:[DJDKMIMOMColor messageTextColor] + range:NSMakeRange(0, msgStr.length)]; + [msgStr addAttribute:NSFontAttributeName + value:kFontRegular(kRoomMessageDefalutFont) + range:NSMakeRange(0, msgStr.length)]; + if ([nickNameNifo isKindOfClass:[NSArray class]]) { + for (NSString *nick in nickNameNifo) { + NSRange range = [message.text rangeOfString:nick]; + if (range.length) { + [msgStr yy_setTextHighlightRange:range color:UIColorFromRGB(0xFD85C9) backgroundColor:[UIColor clearColor] userInfo:nil]; } } } [attribute appendAttributedString:msgStr]; } - if(messageInfo.isChatHall == NO){ - [self attributeAddLongPressHihtLight:attribute uid:message.from nick:((NIMMessageChatroomExtension *)message.messageExt).roomNickname]; - } + + [self attributeAddLongPressHihtLight:attribute uid:message.from nick:((NIMMessageChatroomExtension *)message.messageExt).roomNickname]; + messageInfo.cellKey = @"ChatMessage"; messageInfo.content = attribute; - messageInfo.vipIcon = model.vipIcon; + return messageInfo; } @@ -580,7 +541,6 @@ if ([attribute.string containsString:[NSString stringWithFormat:@"{%@}",model.key]]){ [attribute replaceCharactersInRange:[attribute.string rangeOfString:[NSString stringWithFormat:@"{%@}",model.key]] withAttributedString:attImage]; } - } } messageInfo.content = attribute; @@ -1392,15 +1352,42 @@ #pragma mark - private base methods ///铭牌 -- (NSMutableAttributedString *)createNameplateAttibute:(NSString *)tagName image:(NSString *)imageName textFont:(UIFont *)textFont { +- (NSMutableAttributedString *)createNameplateAttibute:(NSString *)tagName + image:(NSString *)imageName + textFont:(UIFont *)textFont { NetImageConfig *config = [[NetImageConfig alloc]init]; ///先这样吧 + CGSize defaultSize = CGSizeMake(60, kFontRegular(kRoomMessageDefalutFont).lineHeight); config.autoLoad = YES; NetImageView *imageView = [[NetImageView alloc] initWithUrl:imageName config:config]; - UIImage* image = imageView.image; + imageView.bounds = CGRectMake(0, 0, defaultSize.width, defaultSize.height); + + // 异步加载图片 + @kWeakify(self); + [imageView loadImageWithUrl:imageName completion:^(UIImage * _Nullable image, NSURL * _Nonnull url) { + @kStrongify(self); + if (image) { + CGFloat scale = image.size.width / image.size.height; + CGSize newSize = scale > 0 ? CGSizeMake(60 * scale, kFontRegular(kRoomMessageDefalutFont).lineHeight) : defaultSize; + dispatch_async(dispatch_get_main_queue(), ^{ + imageView.bounds = CGRectMake(0, 0, newSize.width, newSize.height); + }); + } + }]; +// [imageView loadImageWithUrl:imageName completion:^(UIImage * _Nullable loadedImage) { +// @kStrongify(self); +// if (loadedImage) { +// CGFloat scale = loadedImage.size.width / loadedImage.size.height; +// CGSize newSize = scale > 0 ? CGSizeMake(18 * scale, 18) : defaultSize; +// dispatch_async(dispatch_get_main_queue(), ^{ +// imageView.bounds = CGRectMake(0, 0, newSize.width, newSize.height); +// }); +// } +// }]; + +// UIImage* image = imageView.image; // if (image) { // CGFloat scale = image.size.width / image.size.height; -// imageView.bounds = CGRectMake(0, 0, 18 * scale, 18); // } else { // NSURL *imgUrl = [NSURL URLWithString:imageName]; // UIImage *myImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:imgUrl]]; @@ -1412,9 +1399,10 @@ // imageView.bounds = CGRectMake(0, 0, 18* scale, 18); // } // } else { - imageView.bounds = CGRectMake(0, 0, 60, 18); +// imageView.bounds = CGRectMake(0, 0, 60, 18); // } // } + imageView.contentMode = UIViewContentModeScaleAspectFit; // 铭牌文字 if (![NSString isEmpty:tagName]) { @@ -1432,7 +1420,11 @@ }]; } - NSMutableAttributedString *string = [NSMutableAttributedString yy_attachmentStringWithContent:imageView contentMode:UIViewContentModeScaleAspectFit attachmentSize:imageView.bounds.size alignToFont:[UIFont boldSystemFontOfSize:12] alignment:YYTextVerticalAlignmentCenter]; + NSMutableAttributedString *string = [NSMutableAttributedString yy_attachmentStringWithContent:imageView + contentMode:UIViewContentModeScaleAspectFit + attachmentSize:imageView.bounds.size + alignToFont:kFontRegular(kRoomMessageDefalutFont) + alignment:YYTextVerticalAlignmentCenter]; return string; } @@ -1453,7 +1445,7 @@ } imageView.layer.masksToBounds = YES; imageView.contentMode = UIViewContentModeScaleAspectFit; - NSMutableAttributedString * attrString = [NSMutableAttributedString yy_attachmentStringWithContent:imageView contentMode:UIViewContentModeScaleAspectFit attachmentSize:CGSizeMake(imageView.bounds.size.width, imageView.bounds.size.height) alignToFont:[UIFont systemFontOfSize:15.0] alignment:YYTextVerticalAlignmentCenter]; + NSMutableAttributedString * attrString = [NSMutableAttributedString yy_attachmentStringWithContent:imageView contentMode:UIViewContentModeScaleAspectFit attachmentSize:CGSizeMake(imageView.bounds.size.width, imageView.bounds.size.height) alignToFont:kFontRegular(kRoomMessageDefalutFont) alignment:YYTextVerticalAlignmentCenter]; return attrString; } /// 生成一个图片的富文本 @@ -1467,7 +1459,7 @@ imageView.bounds = CGRectMake(0, 0, size.width, size.height); imageView.layer.masksToBounds = YES; imageView.contentMode = UIViewContentModeScaleAspectFit; - NSMutableAttributedString * attrString = [NSMutableAttributedString yy_attachmentStringWithContent:imageView contentMode:UIViewContentModeScaleAspectFit attachmentSize:CGSizeMake(imageView.bounds.size.width, imageView.bounds.size.height) alignToFont:[UIFont systemFontOfSize:15.0] alignment:YYTextVerticalAlignmentCenter]; + NSMutableAttributedString * attrString = [NSMutableAttributedString yy_attachmentStringWithContent:imageView contentMode:UIViewContentModeScaleAspectFit attachmentSize:CGSizeMake(imageView.bounds.size.width, imageView.bounds.size.height) alignToFont:kFontRegular(kRoomMessageDefalutFont) alignment:YYTextVerticalAlignmentCenter]; return attrString; } @@ -1481,7 +1473,7 @@ imaveView.image = [UIImage imageNamed:imageName]; CGFloat scale = (CGFloat)imaveView.image.size.width / (CGFloat)imaveView.image.size.height; imaveView.bounds = CGRectMake(0, 0, 16 * scale, 16); - NSMutableAttributedString * attrString = [NSMutableAttributedString yy_attachmentStringWithContent:imaveView contentMode:UIViewContentModeScaleAspectFit attachmentSize:CGSizeMake(imaveView.frame.size.width, imaveView.frame.size.height) alignToFont:[UIFont systemFontOfSize:15.0] alignment:YYTextVerticalAlignmentCenter]; + NSMutableAttributedString * attrString = [NSMutableAttributedString yy_attachmentStringWithContent:imaveView contentMode:UIViewContentModeScaleAspectFit attachmentSize:CGSizeMake(imaveView.frame.size.width, imaveView.frame.size.height) alignToFont:kFontRegular(kRoomMessageDefalutFont) alignment:YYTextVerticalAlignmentCenter]; return attrString; } diff --git a/YuMi/Modules/YMRoom/View/MessageContainerView/View/XPNetImageYYLabel.m b/YuMi/Modules/YMRoom/View/MessageContainerView/View/XPNetImageYYLabel.m index 6f0097a4..555024b4 100644 --- a/YuMi/Modules/YMRoom/View/MessageContainerView/View/XPNetImageYYLabel.m +++ b/YuMi/Modules/YMRoom/View/MessageContainerView/View/XPNetImageYYLabel.m @@ -68,7 +68,11 @@ size = CGSizeMake(16, 16); imageView.bounds = CGRectMake(0, 0, 16, 16); } - NSMutableAttributedString * replaceAttr = [NSMutableAttributedString yy_attachmentStringWithContent:imageView contentMode:UIViewContentModeScaleAspectFit attachmentSize:size alignToFont:[UIFont systemFontOfSize:15.0] alignment:YYTextVerticalAlignmentCenter]; + NSMutableAttributedString * replaceAttr = [NSMutableAttributedString yy_attachmentStringWithContent:imageView + contentMode:UIViewContentModeScaleAspectFit + attachmentSize:size + alignToFont:kFontRegular(kRoomMessageDefalutFont) + alignment:YYTextVerticalAlignmentCenter]; [attributes replaceCharactersInRange:range withAttributedString:replaceAttr]; return attributes; } diff --git a/YuMi/Modules/YMRoom/View/MessageContainerView/View/XPRoomMessageTableViewCell.m b/YuMi/Modules/YMRoom/View/MessageContainerView/View/XPRoomMessageTableViewCell.m index 9e3821ab..27464366 100644 --- a/YuMi/Modules/YMRoom/View/MessageContainerView/View/XPRoomMessageTableViewCell.m +++ b/YuMi/Modules/YMRoom/View/MessageContainerView/View/XPRoomMessageTableViewCell.m @@ -41,8 +41,11 @@ #pragma mark - Private Method - (void)initSubViews { + self.clipsToBounds = NO; + self.contentView.clipsToBounds = NO; + self.selectionStyle = UITableViewCellSelectionStyleNone; - self.backgroundColor = [UIColor clearColor]; + self.backgroundColor = [UIColor colorWithRed:arc4random()%255/255.0 green:arc4random()%255/255.0 blue:arc4random()%255/255.0 alpha:0.4];//[UIColor clearColor]; [self.contentView addSubview:self.bubbleImageView]; [self.contentView addSubview:self.contentLabel]; UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTap)]; @@ -56,19 +59,16 @@ - (void)initSubViewConstraints { [self.bubbleImageView mas_makeConstraints:^(MASConstraintMaker *make) { - make.leading.mas_equalTo(self.contentLabel).offset(-12); - make.top.mas_equalTo(self.contentLabel).offset(-10); - make.bottom.mas_equalTo(self.contentLabel).offset(10); - make.trailing.mas_equalTo(self.contentLabel).offset(10); + 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.trailing.mas_equalTo(self.contentLabel).offset(20); }]; [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.leading.mas_equalTo(12); make.bottom.mas_equalTo(-20); make.top.mas_equalTo(10); - if (isMSRTL()) { - make.width.mas_equalTo(20); - } }]; } @@ -129,50 +129,79 @@ } #pragma mark - Getters And Setters - (void)setMessageInfo:(XPMessageInfoModel *)messageInfo { + if ([messageInfo.content isEqualToAttributedString:_messageInfo.content]) { + return; + } _messageInfo = messageInfo; - if (_messageInfo) { - self.contentLabel.attributedText = _messageInfo.content; + if (messageInfo) { + +// [self.contentLabel mas_updateConstraints:^(MASConstraintMaker *make) { +// make.leading.mas_equalTo(self.bubbleImageView).offset(_messageInfo.contentLeftMargin); +// make.top.mas_equalTo(self.bubbleImageView).offset(_messageInfo.contentTopMargin); +// make.bottom.mas_equalTo(self.bubbleImageView).offset(-_messageInfo.contentBottomMargin); +// }]; + + self.contentLabel.attributedText = messageInfo.content; +// self.contentLabel.textLayout = messageInfo.textLayout; - if (_messageInfo.bubbleImageUrl.length) { + if (messageInfo.bubbleImageUrl.length) { @kWeakify(self); - [self.bubbleImageView loadImageWithUrl:_messageInfo.bubbleImageUrl completion:^(UIImage * _Nonnull image, NSURL * _Nonnull url) { + [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]; }]; - } - - if (self.isLeftBigImage) { - self.leftBigImageView.imageUrl = messageInfo.boomImageUrl; - [self.contentLabel mas_updateConstraints:^(MASConstraintMaker *make) { - make.leading.mas_equalTo(self.leftBigImageView.mas_trailing); - make.trailing.mas_equalTo(-self.messageInfo.contentRightMargin - 8); -// make.centerY.mas_equalTo(self.contentView); - make.top.mas_equalTo(self.bubbleImageView).offset(self.messageInfo.contentTopMargin); - make.bottom.mas_equalTo(self.bubbleImageView).offset(-self.messageInfo.contentBottomMargin); -// if (isMSRTL()) { -// make.width.mas_equalTo([self RTLLabelWidth] - 65); -// } - }]; - } else { - [self.contentLabel mas_updateConstraints:^(MASConstraintMaker *make) { - make.leading.mas_equalTo(self.bubbleImageView).offset(self.messageInfo.contentLeftMargin); - make.top.mas_equalTo(self.bubbleImageView).offset(self.messageInfo.contentTopMargin); - make.bottom.mas_equalTo(self.bubbleImageView).offset(-self.messageInfo.contentBottomMargin); + [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_equalTo([self RTLLabelWidth]); + make.width.mas_greaterThanOrEqualTo([self RTLLabelWidth]); } }]; + } else { + 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]); +// } + }]; } + +// if (self.isLeftBigImage) { +// self.leftBigImageView.imageUrl = messageInfo.boomImageUrl; +// [self.contentLabel mas_updateConstraints:^(MASConstraintMaker *make) { +// make.leading.mas_equalTo(self.leftBigImageView.mas_trailing); +// make.trailing.mas_equalTo(-self.messageInfo.contentRightMargin - 8); +//// make.centerY.mas_equalTo(self.contentView); +// make.top.mas_equalTo(self.bubbleImageView).offset(self.messageInfo.contentTopMargin); +// make.bottom.mas_equalTo(self.bubbleImageView).offset(-self.messageInfo.contentBottomMargin); +//// if (isMSRTL()) { +//// make.width.mas_equalTo([self RTLLabelWidth] - 65); +//// } +// }]; +// } else { + +// } - _bubbleImageView.hidden = _messageInfo.isHiddenBubble; -// [self layoutIfNeeded]; +// _bubbleImageView.hidden = _messageInfo.isHiddenBubble; + [self layoutIfNeeded]; } } - (CGFloat)RTLLabelWidth { - return MIN(self.contentLabel.textWidth + self.messageInfo.contentLeftMargin + self.messageInfo.contentRightMargin + 8, self.contentLabel.maxWidth); + 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); } - (UIImage *)scaleToSize:(UIImage *)img { @@ -207,6 +236,7 @@ - (NetImageView *)bubbleImageView { if (!_bubbleImageView) { _bubbleImageView = [[NetImageView alloc] init]; + _bubbleImageView.clipsToBounds = NO; _bubbleImageView.userInteractionEnabled = YES; _bubbleImageView.layer.masksToBounds = YES; _bubbleImageView.layer.cornerRadius = 7; diff --git a/YuMi/Modules/YMRoom/View/MessageContainerView/XPRoomMessageContainerView.m b/YuMi/Modules/YMRoom/View/MessageContainerView/XPRoomMessageContainerView.m index 3600ad6b..6393a44a 100644 --- a/YuMi/Modules/YMRoom/View/MessageContainerView/XPRoomMessageContainerView.m +++ b/YuMi/Modules/YMRoom/View/MessageContainerView/XPRoomMessageContainerView.m @@ -105,7 +105,7 @@ NSString * const kRoomShowTopicKey = @"kRoomShowTopicKey"; - (void)changeType:(NSInteger)type { self.displayType = type; - [self updateAllDataSource]; +// [self updateAllDataSource]; [self.messageTableView reloadData]; if (self.displayType == 1) { @@ -119,11 +119,15 @@ NSString * const kRoomShowTopicKey = @"kRoomShowTopicKey"; }); } -- (void)updateAllDataSource { - self.datasource_chat = @[].mutableCopy; - self.datasource_gift = @[].mutableCopy; - - for (XPMessageInfoModel *model in self.datasource) { +/// 更新其他 tag 的数据源,若传入空数组,则初始化并从 datasource 中获取数据 +- (void)updateAllDataSource:(NSArray *)datas { + if (!datas || datas.count == 0) { + self.datasource_chat = @[].mutableCopy; + self.datasource_gift = @[].mutableCopy; + datas = self.datasource; + } + + for (XPMessageInfoModel *model in datas) { switch (model.first) { case NIMMessageTypeText: [self.datasource_chat addObject:model]; @@ -198,7 +202,7 @@ NSString * const kRoomShowTopicKey = @"kRoomShowTopicKey"; NSIndexSet *set = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, kRoomMessageMaxLength/2)]; NSArray *needRemoveMsgArray = [self.datasource objectsAtIndexes:set]; [self.datasource removeObjectsInArray:needRemoveMsgArray]; - [self updateAllDataSource]; + [self updateAllDataSource:nil]; NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet]; for (int i = 0; i indexPath.row) { @@ -306,6 +313,7 @@ NSString * const kRoomShowTopicKey = @"kRoomShowTopicKey"; #pragma mark - Private Method - (void)initSubViews { + self.clipsToBounds = YES; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(addCustomMessage:) name:@"message" object:nil]; [self addSubview:self.messageTableView]; [self addSubview:self.messageTipsBtn]; @@ -379,7 +387,6 @@ NSString * const kRoomShowTopicKey = @"kRoomShowTopicKey"; } } - if (self.isPending) { self.messageTipsBtn.hidden = NO; [self findAtMeNumber]; @@ -402,26 +409,26 @@ NSString * const kRoomShowTopicKey = @"kRoomShowTopicKey"; [self.datasource removeObjectsInArray:needRemoveMsgArray]; } - // 执行插入 - // for (NIMMessage *item in self.incomingMessages) { - // XPMessageInfoModel *model = [self.messageParser parseMessageAttribute:item]; - // [self.datasource addObject:model]; - // } + + NSMutableArray *tempArray = @[].mutableCopy; + @kWeakify(self); [self.incomingMessages enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { + @kStrongify(self); + id model = nil; if ([obj isKindOfClass:[NIMMessage class]]) { - XPMessageInfoModel *model = [self.messageParser parseMessageAttribute:(NIMMessage *)obj]; - [self.datasource addObject:model]; + model = [self.messageParser parseMessageAttribute:(NIMMessage *)obj]; } else if ([obj isKindOfClass:[NIMBroadcastMessage class]]) { - XPMessageInfoModel *model = [self.messageParser parseBroadcastMessageAttribute:(NIMBroadcastMessage *)obj]; - if (model) { - [self.datasource addObject:model]; - } + model = [self.messageParser parseBroadcastMessageAttribute:(NIMBroadcastMessage *)obj]; + } + if (model) { + [tempArray addObject:model]; + [self.datasource addObject:model]; } }]; - [self updateAllDataSource]; - [self.incomingMessages removeAllObjects]; + + [self updateAllDataSource:tempArray]; [self.messageTableView reloadData]; //执行插入动画并滚动 @@ -746,9 +753,10 @@ NSString * const kRoomShowTopicKey = @"kRoomShowTopicKey"; NIMCustomObject *obj = (NIMCustomObject *)message.messageObject; if (obj.attachment != nil && [obj.attachment isKindOfClass:[AttachmentModel class]]) { AttachmentModel *attachment = (AttachmentModel *)obj.attachment; - if (attachment.first == CustomMessageType_Update_RoomInfo && attachment.second == Custom_Message_Sub_Update_RoomInfo_MessageState) { + if (attachment.first == CustomMessageType_Update_RoomInfo && + attachment.second == Custom_Message_Sub_Update_RoomInfo_MessageState) { [self.datasource removeAllObjects]; - [self updateAllDataSource]; + [self updateAllDataSource:nil]; [self.incomingMessages removeAllObjects]; [self.locationArray removeAllObjects]; self.atCount = 0; @@ -758,9 +766,10 @@ NSString * const kRoomShowTopicKey = @"kRoomShowTopicKey"; [[XPRoomMiniManager shareManager] resetLocalMessage]; [self addRoomMessage:message]; return; - } else if (attachment.first == CustomMessageType_Update_RoomInfo && attachment.second == Custom_Message_Sub_Update_RoomInfo_CleanScreen) { + } else if (attachment.first == CustomMessageType_Update_RoomInfo && + attachment.second == Custom_Message_Sub_Update_RoomInfo_CleanScreen) { [self.datasource removeAllObjects]; - [self updateAllDataSource]; + [self updateAllDataSource:nil]; [self.incomingMessages removeAllObjects]; [self.locationArray removeAllObjects]; self.atCount = 0; @@ -770,7 +779,8 @@ NSString * const kRoomShowTopicKey = @"kRoomShowTopicKey"; [[XPRoomMiniManager shareManager] resetLocalMessage]; [self addRoomMessage:message]; return; - } else if(attachment.first == CustomMessageType_Candy_Tree && attachment.second == Custom_Message_Sub_Candy_Tree_Me) { + } else if(attachment.first == CustomMessageType_Candy_Tree && + attachment.second == Custom_Message_Sub_Candy_Tree_Me) { CandyTreeGiftInfoModel * model = [CandyTreeGiftInfoModel modelWithDictionary:attachment.data]; if (model.uid.integerValue != [AccountInfoStorage instance].getUid.integerValue) { return; @@ -862,6 +872,50 @@ NSString * const kRoomShowTopicKey = @"kRoomShowTopicKey"; } } +- (void)handleFetchNewestMessage:(NIMMessage *)message { + RoomInfoModel * roomInfo = self.hostDelegate.getRoomInfo; + NSString *roomId = [NSString stringWithFormat:@"%ld", self.hostDelegate.getRoomInfo.roomId]; + NIMHistoryMessageSearchOption *option = [[NIMHistoryMessageSearchOption alloc] init]; + option.limit = [ClientConfig shareConfig].configInfo.roomMessageCount; + option.order = NIMMessageSearchOrderDesc; + option.messageTypes = @[@(NIMMessageTypeText),@(NIMMessageTypeCustom)]; + @kWeakify(self); + [[NIMSDK sharedSDK].chatroomManager fetchMessageHistory:roomId + option:option + result:^(NSError * _Nullable error, NSArray * _Nullable messages) { + @kStrongify(self); + if(error != nil){ + self.isLoadHistoryMessage = NO; + } + if (self.datasource.count > kRoomMessageMaxLength) { + NSIndexSet *set = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, kRoomMessageMaxLength/2)]; + NSArray *needRemoveMsgArray = [self.datasource objectsAtIndexes:set]; + [self.datasource removeObjectsInArray:needRemoveMsgArray]; + } + // 执行插入 + for (NIMMessage *item in messages.reverseObjectEnumerator) { + [self dealWithHistoryDataWithMessage:item]; + } + self.isLoadHistoryMessage = NO; + BOOL hideEnter = [self handleHideEnter:message]; + if (!hideEnter) { + ///插入进房消息及房间公告提示 + [self addRoomMessage:message]; + } + if (!roomInfo.hasAnimationEffect) { + [self roomInfoNoGiftAnimationMessage:message]; + } + [self createUserEnterRoomAddRoomTopicMessage]; + + [self updateAllDataSource:nil]; + + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + [self.messageTableView reloadData]; + [self scrollToBottom:YES]; + }); + }]; +} + - (void)handleFetchHistoryMessage:(NIMMessage *)message { RoomInfoModel * roomInfo = self.hostDelegate.getRoomInfo; NSString *roomId = [NSString stringWithFormat:@"%ld", self.hostDelegate.getRoomInfo.roomId]; @@ -870,79 +924,45 @@ NSString * const kRoomShowTopicKey = @"kRoomShowTopicKey"; option.startTime = self.hostDelegate.getRoomInfo.clearScreenTime / 1000.0; option.order = NIMMessageSearchOrderAsc; option.messageTypes = @[@(NIMMessageTypeText),@(NIMMessageTypeCustom)]; - [[NIMSDK sharedSDK].chatroomManager fetchMessageHistory:roomId option:option result:^(NSError * _Nullable error, NSArray * _Nullable messages) { + [[NIMSDK sharedSDK].chatroomManager fetchMessageHistory:roomId + option:option + result:^(NSError * _Nullable error, NSArray * _Nullable messages) { if(error != nil){ - self.isLoadHistoryMessage = NO; + self.isLoadHistoryMessage = NO; } if (messages.count) { //如果拉取的数量等于请求的数量,说明这个时间点以后的消息数量大于等于需要拉取的数量,直接拉取最新的50条 if (messages.count == [ClientConfig shareConfig].configInfo.roomMessageCount) { - NIMHistoryMessageSearchOption *option = [[NIMHistoryMessageSearchOption alloc] init]; - option.limit = [ClientConfig shareConfig].configInfo.roomMessageCount; - option.order = NIMMessageSearchOrderDesc; - option.messageTypes = @[@(NIMMessageTypeText),@(NIMMessageTypeCustom)]; - @kWeakify(self); - [[NIMSDK sharedSDK].chatroomManager fetchMessageHistory:roomId option:option result:^(NSError * _Nullable error, NSArray * _Nullable messages) { - @kStrongify(self); - if(error != nil){ - self.isLoadHistoryMessage = NO; - } - if (self.datasource.count > kRoomMessageMaxLength) { - NSIndexSet *set = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, kRoomMessageMaxLength/2)]; - NSArray *needRemoveMsgArray = [self.datasource objectsAtIndexes:set]; - [self.datasource removeObjectsInArray:needRemoveMsgArray]; - } - // 执行插入 - for (NIMMessage *item in messages.reverseObjectEnumerator) { - [self dealWithHistoryDataWithMessage:item]; - } - self.isLoadHistoryMessage = NO; - BOOL hideEnter = [self handleHideEnter:message]; - if (!hideEnter) { - ///插入进房消息及房间公告提示 - [self addRoomMessage:message]; - } - if (!roomInfo.hasAnimationEffect) { - [self roomInfoNoGiftAnimationMessage:message]; - } - [self createUserEnterRoomAddRoomTopicMessage]; + [self handleFetchNewestMessage:message]; + } else { + if (self.datasource.count > kRoomMessageMaxLength) { + NSIndexSet *set = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, kRoomMessageMaxLength/2)]; + NSArray *needRemoveMsgArray = [self.datasource objectsAtIndexes:set]; + [self.datasource removeObjectsInArray:needRemoveMsgArray]; + } + // 执行插入 + for (NIMMessage *item in messages) { + [self dealWithHistoryDataWithMessage:item]; + } - [self updateAllDataSource]; + self.isLoadHistoryMessage = NO; + BOOL hideEnter = [self handleHideEnter:message]; + if (!hideEnter) { + ///插入进房消息及房间公告提示 + [self addRoomMessage:message]; + } + if (!roomInfo.hasAnimationEffect) { + [self roomInfoNoGiftAnimationMessage:message]; + } + [self createUserEnterRoomAddRoomTopicMessage]; - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - [self.messageTableView reloadData]; - [self scrollToBottom:YES]; - }); - }]; - return; - } - if (self.datasource.count > kRoomMessageMaxLength) { - NSIndexSet *set = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, kRoomMessageMaxLength/2)]; - NSArray *needRemoveMsgArray = [self.datasource objectsAtIndexes:set]; - [self.datasource removeObjectsInArray:needRemoveMsgArray]; - } - // 执行插入 - for (NIMMessage *item in messages) { - [self dealWithHistoryDataWithMessage:item]; - } + [self updateAllDataSource:nil]; - self.isLoadHistoryMessage = NO; - BOOL hideEnter = [self handleHideEnter:message]; - if (!hideEnter) { - ///插入进房消息及房间公告提示 - [self addRoomMessage:message]; + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + [self.messageTableView reloadData]; + [self scrollToBottom:YES]; + }); } - if (!roomInfo.hasAnimationEffect) { - [self roomInfoNoGiftAnimationMessage:message]; - } - [self createUserEnterRoomAddRoomTopicMessage]; - - [self updateAllDataSource]; - - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - [self.messageTableView reloadData]; - [self scrollToBottom:YES]; - }); }else{ dispatch_async(dispatch_get_main_queue(), ^{///回到主线程 self.isLoadHistoryMessage = NO; @@ -1013,20 +1033,22 @@ NSString * const kRoomShowTopicKey = @"kRoomShowTopicKey"; self.isLoadHistoryMessage = NO; ///最小化进房 不需要请求任何接口 但是如果不加延迟的话 无法滚动到底部 原因还不知道 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + NSMutableArray *tempArray = @[].mutableCopy; NSArray * temArray = [XPRoomMiniManager shareManager].getLocalCurrentRoomMessage; [temArray enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { + id model = nil; if ([obj isKindOfClass:[NIMMessage class]]) { - XPMessageInfoModel *model = [self.messageParser parseMessageAttribute:(NIMMessage *)obj]; - [self.datasource addObject:model]; + model = [self.messageParser parseMessageAttribute:(NIMMessage *)obj]; } else if ([obj isKindOfClass:[NIMBroadcastMessage class]]) { - XPMessageInfoModel *model = [self.messageParser parseBroadcastMessageAttribute:(NIMBroadcastMessage *)obj]; - if (model) { - [self.datasource addObject:model]; - } + model = [self.messageParser parseBroadcastMessageAttribute:(NIMBroadcastMessage *)obj]; + } + if (model) { + [tempArray addObject:model]; + [self.datasource addObject:model]; } }]; - [self updateAllDataSource]; + [self updateAllDataSource:tempArray]; [self.messageTableView reloadData]; //执行插入动画并滚动 [self scrollToBottom:YES]; @@ -1096,34 +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; - } - - // 否则,使用自适应高度 - return UITableViewAutomaticDimension; -} +//- (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; +//} - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { switch (self.displayType) { @@ -1161,7 +1184,7 @@ NSString * const kRoomShowTopicKey = @"kRoomShowTopicKey"; break; } XPMessageInfoModel *model = [source xpSafeObjectAtIndex:indexPath.row]; - NSString *cellKey = NSStringFromClass([XPRoomMessageTableViewCell class]); + NSString *cellKey = [NSString isEmpty:model.cellKey] ? NSStringFromClass([XPRoomMessageTableViewCell class]) : model.cellKey; if(model.first == CustomMessageType_Room_Album){ PIRoomMessagePhotoAlbumCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([PIRoomMessagePhotoAlbumCell class])]; cell.delegate = self; @@ -1182,7 +1205,7 @@ NSString * const kRoomShowTopicKey = @"kRoomShowTopicKey"; return cell; } -- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { +//- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { // NSArray *source = @[]; // switch (self.displayType) { // case 1: @@ -1203,7 +1226,7 @@ NSString * const kRoomShowTopicKey = @"kRoomShowTopicKey"; // if (model.rowHeight == 0) { // model.rowHeight = CGRectGetHeight(cell.frame); // } -} +//} #pragma mark - XPRoomMessageTableViewCellDelegate @@ -1313,18 +1336,20 @@ NSString * const kRoomShowTopicKey = @"kRoomShowTopicKey"; _messageTableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain]; _messageTableView.delegate = self; _messageTableView.dataSource = self; - _messageTableView.rowHeight = UITableViewAutomaticDimension; - _messageTableView.estimatedRowHeight = 44; // 预估高度 +// _messageTableView.rowHeight = UITableViewAutomaticDimension; +// _messageTableView.estimatedRowHeight = 44; // 预估高度 _messageTableView.tableFooterView = [UIView new]; _messageTableView.separatorStyle = UITableViewCellSeparatorStyleNone; _messageTableView.backgroundColor = [UIColor clearColor]; _messageTableView.showsVerticalScrollIndicator = NO; + _messageTableView.clipsToBounds = NO; _messageTableView.tag = 666; if (@available(iOS 11.0, *)) { _messageTableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; } [_messageTableView registerClass:[XPRoomMessageTableViewCell class] forCellReuseIdentifier:@"XPRoomMessageTableViewCell_Boom"]; [_messageTableView registerClass:[XPRoomMessageTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPRoomMessageTableViewCell class])]; + [_messageTableView registerClass:[XPRoomMessageTableViewCell class] forCellReuseIdentifier:@"ChatMessage"]; [_messageTableView registerClass:[PIRoomMessagePhotoAlbumCell class] forCellReuseIdentifier:NSStringFromClass([PIRoomMessagePhotoAlbumCell class])]; } diff --git a/YuMi/Modules/YMRoom/View/ThemeColor+Room.m b/YuMi/Modules/YMRoom/View/ThemeColor+Room.m index 2665c7aa..4de685af 100644 --- a/YuMi/Modules/YMRoom/View/ThemeColor+Room.m +++ b/YuMi/Modules/YMRoom/View/ThemeColor+Room.m @@ -53,7 +53,8 @@ ///公屏默认背景的颜色 + (UIColor *)messageBubbleColor { - return UIColorRGBAlpha(0xFFFFFF, 0.15); +// return UIColorRGBAlpha(0xFFFFFF, 0.15); + return UIColorRGBAlpha(0x000000, 0.35); } ///公屏文字的颜色 + (UIColor *)messageTextColor {