新增 emoji 缓存清理功能以确保新的尺寸设置生效,优化表情处理逻辑,支持带场景参数的表情转换。同时,更新相关方法以适应新功能,提升用户体验。
This commit is contained in:
@@ -180,6 +180,9 @@ UIKIT_EXTERN NSString * adImageName;
|
||||
QEmotionHelper *faceManager = [QEmotionHelper sharedEmotionHelper];
|
||||
faceManager.emotionArray = array;
|
||||
|
||||
// 清理 emoji 缓存,确保新的尺寸设置生效
|
||||
[QEmotionHelper clearEmojiCache];
|
||||
|
||||
#if DEBUG
|
||||
// 测试图片加载
|
||||
NSLog(@"表情数组加载完成,总数: %lu", (unsigned long)array.count);
|
||||
|
@@ -25,7 +25,17 @@
|
||||
//把 @"[微笑]" 转为 @"😊"
|
||||
- (NSAttributedString *)obtainAttributedStringByImageKey:(NSString *)imageKey font:(UIFont *)font useCache:(BOOL)useCache;
|
||||
|
||||
//imageKey:[微笑] font:label的Font,返回😊 (带场景参数)
|
||||
//把 @"[微笑]" 转为 @"😊"
|
||||
- (NSAttributedString *)obtainAttributedStringByImageKey:(NSString *)imageKey font:(UIFont *)font useCache:(BOOL)useCache forMessageBubble:(BOOL)isMessageBubble;
|
||||
|
||||
//把 @"害~你好啊[微笑]" 转为 @"害~你好啊😊"
|
||||
- (NSMutableAttributedString *)attributedStringByText:(NSString *)text font:(UIFont *)font;
|
||||
|
||||
//把 @"害~你好啊[微笑]" 转为 @"害~你好啊😊" (带场景参数)
|
||||
- (NSMutableAttributedString *)attributedStringByText:(NSString *)text font:(UIFont *)font forMessageBubble:(BOOL)isMessageBubble;
|
||||
|
||||
// 清理 emoji 缓存,用于尺寸变更后刷新
|
||||
+ (void)clearEmojiCache;
|
||||
|
||||
@end
|
||||
|
@@ -46,6 +46,12 @@
|
||||
return _sharedFaceManager;
|
||||
}
|
||||
|
||||
// 清理 emoji 缓存,用于尺寸变更后刷新
|
||||
+ (void)clearEmojiCache {
|
||||
QEmotionHelper *helper = [QEmotionHelper sharedEmotionHelper];
|
||||
[helper.cacheAttributedDictionary removeAllObjects];
|
||||
}
|
||||
|
||||
#pragma mark - public
|
||||
//本方法我这里只是demo演示;实际开发中,可以改为你自己的获取表情列表的写法
|
||||
//由于emotionArray包含Image,测试结果是占用0.5MB的内存(永驻)
|
||||
@@ -78,6 +84,11 @@
|
||||
|
||||
//把整段String:@"害~你好[微笑]", 转为 @"害~你好😊"
|
||||
- (NSMutableAttributedString *)attributedStringByText:(NSString *)text font:(UIFont *)font {
|
||||
return [self attributedStringByText:text font:font forMessageBubble:NO];
|
||||
}
|
||||
|
||||
//把整段String:@"害~你好[微笑]", 转为 @"害~你好😊" (带场景参数)
|
||||
- (NSMutableAttributedString *)attributedStringByText:(NSString *)text font:(UIFont *)font forMessageBubble:(BOOL)isMessageBubble {
|
||||
if(text.length == 0){
|
||||
return [[NSMutableAttributedString alloc] initWithString:@""];;
|
||||
}
|
||||
@@ -98,7 +109,7 @@
|
||||
//ios15他采用了NSTextAttachmentViewProvider,具体我没研究
|
||||
useCache = NO;
|
||||
}
|
||||
NSAttributedString *imageAttributedString = [self obtainAttributedStringByImageKey:emojiKey font:font useCache:useCache];
|
||||
NSAttributedString *imageAttributedString = [self obtainAttributedStringByImageKey:emojiKey font:font useCache:useCache forMessageBubble:isMessageBubble];
|
||||
if (imageAttributedString) {
|
||||
[intactAttributeString replaceCharactersInRange:result.range withAttributedString:imageAttributedString];
|
||||
}
|
||||
@@ -115,6 +126,13 @@
|
||||
//imageKey:[微笑] ,font:label的Font,返回😊
|
||||
//把 @@"[微笑]", 转为 @"😊"
|
||||
- (NSAttributedString *)obtainAttributedStringByImageKey:(NSString *)imageKey font:(UIFont *)font useCache:(BOOL)useCache {
|
||||
return [self obtainAttributedStringByImageKey:imageKey font:font useCache:useCache forMessageBubble:NO];
|
||||
}
|
||||
|
||||
//把只是单纯的一个表情转为AttributedString (带场景参数)
|
||||
//imageKey:[微笑] ,font:label的Font,返回😊
|
||||
//把 @@"[微笑]", 转为 @"😊"
|
||||
- (NSAttributedString *)obtainAttributedStringByImageKey:(NSString *)imageKey font:(UIFont *)font useCache:(BOOL)useCache forMessageBubble:(BOOL)isMessageBubble {
|
||||
if([self.emojiHantList containsObject:imageKey]){
|
||||
NSString *getImageKey = [self.emojiHansList xpSafeObjectAtIndex:[self.emojiHantList indexOfObject:imageKey]];
|
||||
if(getImageKey != nil){
|
||||
@@ -133,14 +151,17 @@
|
||||
imageView.contentMode = UIViewContentModeScaleAspectFit;
|
||||
imageView.displayText = imageKey;
|
||||
imageView.image = image;
|
||||
|
||||
// 计算 emoji 尺寸:根据场景决定是否放大
|
||||
CGFloat emojiSize = isMessageBubble ? font.lineHeight * 2.0 : font.lineHeight; // 消息气泡放大一倍
|
||||
if (image) {
|
||||
CGFloat scale = image.size.width / image.size.height;
|
||||
imageView.bounds = CGRectMake(0, 0, 20 * scale, 20);
|
||||
imageView.bounds = CGRectMake(0, 0, emojiSize * scale, emojiSize);
|
||||
} else {
|
||||
imageView.bounds = CGRectMake(0, 0, 20, 20);
|
||||
imageView.bounds = CGRectMake(0, 0, emojiSize, emojiSize);
|
||||
}
|
||||
imageView.bounds = CGRectMake(0, 0, font.lineHeight, font.lineHeight);
|
||||
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:font alignment:YYTextVerticalAlignmentCenter];
|
||||
return attrString;
|
||||
}
|
||||
|
||||
@@ -165,14 +186,17 @@
|
||||
imageView.contentMode = UIViewContentModeScaleAspectFit;
|
||||
imageView.displayText = imageKey;
|
||||
imageView.image = image;
|
||||
|
||||
// 计算 emoji 尺寸:根据场景决定是否放大
|
||||
CGFloat emojiSize = isMessageBubble ? font.lineHeight * 2.0 : font.lineHeight; // 消息气泡放大一倍
|
||||
if (image) {
|
||||
CGFloat scale = image.size.width / image.size.height;
|
||||
imageView.bounds = CGRectMake(0, 0, 20 * scale, 20);
|
||||
imageView.bounds = CGRectMake(0, 0, emojiSize * scale, emojiSize);
|
||||
} else {
|
||||
imageView.bounds = CGRectMake(0, 0, 20, 20);
|
||||
imageView.bounds = CGRectMake(0, 0, emojiSize, emojiSize);
|
||||
}
|
||||
imageView.bounds = CGRectMake(0, 0, font.lineHeight, font.lineHeight);
|
||||
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:font alignment:YYTextVerticalAlignmentCenter];
|
||||
//[微笑]17 对应的NSAttributedString 缓存到Dictionary中
|
||||
[_cacheAttributedDictionary setObject:attrString forKey:keyFont];
|
||||
return result;
|
||||
|
@@ -64,7 +64,7 @@
|
||||
model.message.rawAttachContent];
|
||||
}
|
||||
QEmotionHelper *faceManager = [QEmotionHelper sharedEmotionHelper];
|
||||
NSMutableAttributedString * attribute = [faceManager attributedStringByText:messageText font:[UIFont systemFontOfSize:13]];
|
||||
NSMutableAttributedString * attribute = [faceManager attributedStringByText:messageText font:[UIFont systemFontOfSize:13] forMessageBubble:YES];
|
||||
_messageText.attributedText = attribute;
|
||||
}
|
||||
[_messageText.superview layoutIfNeeded];
|
||||
|
@@ -48,7 +48,7 @@
|
||||
|
||||
CGSize dstRect = CGSizeMake(width, MAXFLOAT);
|
||||
QEmotionHelper *faceManager = [QEmotionHelper sharedEmotionHelper];
|
||||
NSMutableAttributedString * attribute = [faceManager attributedStringByText:messageText font:kFontMedium(14)];
|
||||
NSMutableAttributedString * attribute = [faceManager attributedStringByText:messageText font:kFontMedium(14) forMessageBubble:YES];
|
||||
if(extModel.iosBubbleUrl.length > 0){
|
||||
[attribute addAttributes:@{NSForegroundColorAttributeName: UIColorFromRGB(0x333333)} range:[attribute.string rangeOfString:attribute.string]];
|
||||
}else{
|
||||
|
@@ -34,7 +34,7 @@
|
||||
}
|
||||
CGSize dstRect = CGSizeMake(CONTENT_WIDTH_MAX - MESSAGE_PADDING * 2, MAXFLOAT);
|
||||
QEmotionHelper *faceManager = [QEmotionHelper sharedEmotionHelper];
|
||||
NSMutableAttributedString * attribute = [faceManager attributedStringByText:messageText font:[UIFont systemFontOfSize:13]];
|
||||
NSMutableAttributedString * attribute = [faceManager attributedStringByText:messageText font:[UIFont systemFontOfSize:13] forMessageBubble:YES];
|
||||
self.textAttribute = attribute;
|
||||
YYTextContainer *container = [YYTextContainer containerWithSize:dstRect];
|
||||
container.maximumNumberOfRows = 0;
|
||||
|
@@ -266,8 +266,9 @@
|
||||
if ([[XPSkillCardPlayerManager shareInstance] isInRoomVC]) {
|
||||
[self.boomEventsQueue addObject:attachment];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:@"UpdateWhenBoomExplosion" object:nil];
|
||||
[self.bannerEventsQueue addObject:attachment];
|
||||
}
|
||||
[self.bannerEventsQueue addObject:attachment];
|
||||
// [self.bannerEventsQueue addObject:attachment];
|
||||
|
||||
[self checkAndStartBoomEvent];
|
||||
[self checkAndStartBannerEvent];
|
||||
|
@@ -140,6 +140,9 @@ UIKIT_EXTERN NSString *kTabShowAnchorCardKey;
|
||||
[[NIMSDK sharedSDK].chatManager removeDelegate:self];
|
||||
[[NIMSDK sharedSDK].systemNotificationManager removeDelegate:self];
|
||||
[[NIMSDK sharedSDK].broadcastManager removeDelegate:self];
|
||||
|
||||
// 🔧 新增:清理 RoomBoomManager 监听器,防止内存泄漏
|
||||
[[RoomBoomManager sharedManager] removeEventListenerForTarget:self];
|
||||
}
|
||||
|
||||
- (void)viewDidLoad {
|
||||
@@ -186,10 +189,13 @@ UIKIT_EXTERN NSString *kTabShowAnchorCardKey;
|
||||
|
||||
[[RoomBoomManager sharedManager] registerBoomBanner:^(id _Nonnull sth) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[RoomBoomBannerAnimation display:kWindow
|
||||
with:sth
|
||||
tapToRoom:YES
|
||||
complete:^{}];
|
||||
// 🔧 新增:检查用户是否在房间中,只有在房间中才显示全局火箭升级通知
|
||||
if ([XPSkillCardPlayerManager shareInstance].isInRoom == YES) {
|
||||
[RoomBoomBannerAnimation display:kWindow
|
||||
with:sth
|
||||
tapToRoom:YES
|
||||
complete:^{}];
|
||||
}
|
||||
});
|
||||
} target:self];
|
||||
|
||||
|
@@ -13,6 +13,7 @@
|
||||
#import "BaseNavigationController.h"
|
||||
#import "FirstRechargeManager.h"
|
||||
#import "PublicRoomManager.h"
|
||||
#import "RoomBoomManager.h"
|
||||
|
||||
@interface BaseMvpPresenter()
|
||||
|
||||
@@ -37,13 +38,16 @@
|
||||
// 2. 重置公共房间管理器
|
||||
[[PublicRoomManager sharedManager] reset];
|
||||
|
||||
// 3. 数据logout
|
||||
// 3. 清理房间火箭管理器状态
|
||||
[[RoomBoomManager sharedManager] leaveRoom];
|
||||
|
||||
// 4. 数据logout
|
||||
[[AccountInfoStorage instance] saveAccountInfo:nil];
|
||||
[[AccountInfoStorage instance] saveTicket:nil];
|
||||
if ([NIMSDK sharedSDK].loginManager.isLogined) {
|
||||
[[NIMSDK sharedSDK].loginManager logout:nil];
|
||||
}
|
||||
// 4. 跳登录页面
|
||||
// 5. 跳登录页面
|
||||
[self tokenInvalid];
|
||||
// ///关闭心跳
|
||||
// [[ClientConfig shareConfig] resetHeartBratTimer];
|
||||
|
Reference in New Issue
Block a user