temp save: 基本完整显示聊天内容
This commit is contained in:
@@ -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
|
||||
|
@@ -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 {
|
||||
|
@@ -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;
|
||||
|
@@ -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,55 +255,40 @@
|
||||
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 createUrlImageAttribute:model.inRoomNameplatePic
|
||||
size:CGSizeMake(60, kFontRegular(kRoomMessageDefalutFont).lineHeight)]];
|
||||
[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]];
|
||||
// }
|
||||
}
|
||||
[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{
|
||||
if (message.text) {
|
||||
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];
|
||||
@@ -335,15 +297,14 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
[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;
|
||||
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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.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(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) {
|
||||
|
||||
if (_messageInfo.bubbleImageUrl.length) {
|
||||
// [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) {
|
||||
@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];
|
||||
}];
|
||||
[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]);
|
||||
}
|
||||
|
||||
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);
|
||||
if (isMSRTL()) { // MARK: 可能会有性能问题,但源代码已经使用了更新 layout 的方案,推测是头像框和气泡会导致卡顿
|
||||
make.width.mas_equalTo([self RTLLabelWidth]);
|
||||
}
|
||||
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]);
|
||||
// }
|
||||
}];
|
||||
}
|
||||
|
||||
_bubbleImageView.hidden = _messageInfo.isHiddenBubble;
|
||||
// [self layoutIfNeeded];
|
||||
// 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];
|
||||
}
|
||||
}
|
||||
|
||||
- (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;
|
||||
|
@@ -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 {
|
||||
/// 更新其他 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 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<self.locationArray.count; i++) {///移除掉前面消息的数据后,前面如果有at我的消息,也一并移除掉
|
||||
NSNumber *number = self.locationArray[i];
|
||||
@@ -216,7 +220,8 @@ NSString * const kRoomShowTopicKey = @"kRoomShowTopicKey";
|
||||
}
|
||||
|
||||
// 执行插入
|
||||
NSMutableArray *indexPaths = [NSMutableArray array];
|
||||
NSMutableArray *indexPaths = @[].mutableCopy;
|
||||
NSMutableArray *tempNewDatas = @[].mutableCopy;
|
||||
for (id item in self.incomingMessages) {
|
||||
XPMessageInfoModel *model = nil;
|
||||
if ([item isKindOfClass:[NIMMessage class]]) {
|
||||
@@ -227,6 +232,7 @@ NSString * const kRoomShowTopicKey = @"kRoomShowTopicKey";
|
||||
if (!model) {
|
||||
continue;
|
||||
}
|
||||
[tempNewDatas addObject:model];
|
||||
[self.datasource addObject:model];
|
||||
[indexPaths addObject:[NSIndexPath indexPathForRow:self.datasource.count - 1 inSection:0]];
|
||||
if ([item isKindOfClass:[NIMMessage class]]) {
|
||||
@@ -240,7 +246,7 @@ NSString * const kRoomShowTopicKey = @"kRoomShowTopicKey";
|
||||
}
|
||||
}
|
||||
}
|
||||
[self updateAllDataSource];
|
||||
[self updateAllDataSource:tempNewDatas];
|
||||
[self.incomingMessages removeAllObjects];
|
||||
[self.messageTableView reloadData];
|
||||
|
||||
@@ -253,6 +259,7 @@ NSString * const kRoomShowTopicKey = @"kRoomShowTopicKey";
|
||||
self.atTipBtn.hidden = YES;
|
||||
return;
|
||||
}
|
||||
|
||||
int index = [self.locationArray[0] intValue];
|
||||
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:index inSection:0];
|
||||
if (rows > 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,27 +872,17 @@ NSString * const kRoomShowTopicKey = @"kRoomShowTopicKey";
|
||||
}
|
||||
}
|
||||
|
||||
- (void)handleFetchHistoryMessage:(NIMMessage *)message {
|
||||
- (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.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<NIMMessage *> * _Nullable messages) {
|
||||
if(error != nil){
|
||||
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<NIMMessage *> * _Nullable messages) {
|
||||
[[NIMSDK sharedSDK].chatroomManager fetchMessageHistory:roomId
|
||||
option:option
|
||||
result:^(NSError * _Nullable error, NSArray<NIMMessage *> * _Nullable messages) {
|
||||
@kStrongify(self);
|
||||
if(error != nil){
|
||||
self.isLoadHistoryMessage = NO;
|
||||
@@ -907,15 +907,34 @@ NSString * const kRoomShowTopicKey = @"kRoomShowTopicKey";
|
||||
}
|
||||
[self createUserEnterRoomAddRoomTopicMessage];
|
||||
|
||||
[self updateAllDataSource];
|
||||
[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];
|
||||
});
|
||||
}];
|
||||
return;
|
||||
}
|
||||
|
||||
- (void)handleFetchHistoryMessage:(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.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<NIMMessage *> * _Nullable messages) {
|
||||
if(error != nil){
|
||||
self.isLoadHistoryMessage = NO;
|
||||
}
|
||||
if (messages.count) {
|
||||
//如果拉取的数量等于请求的数量,说明这个时间点以后的消息数量大于等于需要拉取的数量,直接拉取最新的50条
|
||||
if (messages.count == [ClientConfig shareConfig].configInfo.roomMessageCount) {
|
||||
[self handleFetchNewestMessage:message];
|
||||
} else {
|
||||
if (self.datasource.count > kRoomMessageMaxLength) {
|
||||
NSIndexSet *set = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, kRoomMessageMaxLength/2)];
|
||||
NSArray *needRemoveMsgArray = [self.datasource objectsAtIndexes:set];
|
||||
@@ -937,12 +956,13 @@ NSString * const kRoomShowTopicKey = @"kRoomShowTopicKey";
|
||||
}
|
||||
[self createUserEnterRoomAddRoomTopicMessage];
|
||||
|
||||
[self updateAllDataSource];
|
||||
[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];
|
||||
});
|
||||
}
|
||||
}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])];
|
||||
|
||||
}
|
||||
|
@@ -53,7 +53,8 @@
|
||||
|
||||
///公屏默认背景的颜色
|
||||
+ (UIColor *)messageBubbleColor {
|
||||
return UIColorRGBAlpha(0xFFFFFF, 0.15);
|
||||
// return UIColorRGBAlpha(0xFFFFFF, 0.15);
|
||||
return UIColorRGBAlpha(0x000000, 0.35);
|
||||
}
|
||||
///公屏文字的颜色
|
||||
+ (UIColor *)messageTextColor {
|
||||
|
Reference in New Issue
Block a user