公屏的点击 已经公屏的网络图片自适应大小

This commit is contained in:
fengshuo
2021-10-29 10:50:39 +08:00
parent 7b0f914a9f
commit c1b7d672fc
23 changed files with 323 additions and 56 deletions

View File

@@ -0,0 +1,22 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "common_new_user@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "common_new_user@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 709 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@@ -0,0 +1,22 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "common_offical@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "common_offical@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 451 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 817 B

View File

@@ -37,6 +37,9 @@ typedef NS_ENUM(NSUInteger,ImageType){
+ (UIImage *)defalutEmptyPlaceholder;
/// banner的占位图
+ (UIImage *)defalutBannerPlaceholder;
@end
NS_ASSUME_NONNULL_END

View File

@@ -9,24 +9,26 @@
#import "UIImageConstant.h"
NS_ASSUME_NONNULL_BEGIN
typedef void(^LoadImageSuccess)(UIImage *image, NSURL * url);
@interface UIImageView (LoadImage)
/// 加载图片
/// @param url 图片的链接地址
/// @param placeholderImage 站位图
/// @param type 类型 用于设置大小
/// @param cornerRadious 弧度
/// @param success 成功的回调
/// @param complection 成功的回调
- (void)load_imageWithUrl:(NSString *)url
placeholderImage:(UIImage *)placeholderImage
type:(ImageType)type
cornerRadious:(CGFloat)cornerRadious
success:(void (^)(UIImage *image))success;
complection:(nullable LoadImageSuccess)complection;
/// 加载图片 回调图片的
/// @param url 图片的链接地址
/// @param placeholderImage 站位图
/// @param success 成功了
- (void)load_imageWithUrl:(NSString *)url placeholderImage:(UIImage *)placeholderImage type:(ImageType)type success:(void (^)(UIImage *image))success;
/// @param complection 成功了
- (void)load_imageWithUrl:(NSString *)url placeholderImage:(UIImage *)placeholderImage type:(ImageType)type complection:(nullable LoadImageSuccess)complection;
/// 加载图片不需要成功的回调
/// @param url 图片的链接地址

View File

@@ -16,12 +16,12 @@
/// @param placeholderImage
/// @param type
/// @param cornerRadious
/// @param success
/// @param complection
- (void)load_imageWithUrl:(NSString *)url
placeholderImage:(UIImage *)placeholderImage
type:(ImageType)type
cornerRadious:(CGFloat)cornerRadious
success:(void (^)(UIImage *image))success {
complection:(nullable LoadImageSuccess)complection {
NSMutableString *urlString = [NSMutableString stringWithString:url];
NSString *configUrl = nil;
switch (type) {
@@ -73,17 +73,17 @@
}
NSString *encodeStr = [self URLEncodedString:urlString];
if (placeholderImage) {
[self sd_setImageWithURL:[NSURL URLWithString:encodeStr] placeholderImage:placeholderImage options:SDWebImageRetryFailed completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
if (success) {
success(image);
if (complection) {
complection(image, imageURL);
}
}];
}else{
[self sd_setImageWithURL:[NSURL URLWithString:encodeStr] placeholderImage:nil options:SDWebImageRetryFailed completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
if (success) {
success(image);
if (complection) {
complection(image, imageURL);
}
}];
}
@@ -99,7 +99,7 @@
placeholderImage:(UIImage *)placeholderImage
type:(ImageType)type
cornerRadious:(CGFloat)cornerRadious {
[self load_imageWithUrl:url placeholderImage:placeholderImage type:type cornerRadious:cornerRadious success:nil];
[self load_imageWithUrl:url placeholderImage:placeholderImage type:type cornerRadious:cornerRadious complection:nil];
}
@@ -122,9 +122,9 @@
///
/// @param url
/// @param placeholderImage
/// @param success
- (void)load_imageWithUrl:(NSString *)url placeholderImage:(UIImage *)placeholderImage type:(ImageType)type success:(void (^)(UIImage *image))success{
[self load_imageWithUrl:url placeholderImage:placeholderImage type:type cornerRadious:0 success:success];
/// @param complection
- (void)load_imageWithUrl:(NSString *)url placeholderImage:(UIImage *)placeholderImage type:(ImageType)type complection:(nullable LoadImageSuccess)complection{
[self load_imageWithUrl:url placeholderImage:placeholderImage type:type cornerRadious:0 complection:complection];
}
- (NSString *)URLEncodedString:(NSString *)string

View File

@@ -25,4 +25,7 @@ isPhoneXSeries = [[UIApplication sharedApplication] delegate].window.safeAreaIns
#define kNavigationHeight (kStatusBarHeight + 44)
#define kTabBarHeight (iPhoneXSeries ? 49.0+34.0 : 49.0)
#define kWeakify(o) try{}@finally{} __weak typeof(o) o##Weak = o;
#define kStrongify(o) autoreleasepool{} __strong typeof(o) o = o##Weak;
#endif /* XPMacro_h */

View File

@@ -132,7 +132,7 @@
XPMineUserInfoImageCollectionViewCell * imageCell = (XPMineUserInfoImageCollectionViewCell *)cell;
NSString *url = [self.imageUrls objectAtIndex:index];
@weakify(imageCell);
[imageCell.logoImageView load_imageWithUrl:url placeholderImage:[UIImageConstant defalutBannerPlaceholder] type:ImageTypeUserInfoAlbum success:^(UIImage * _Nonnull image) {
[imageCell.logoImageView load_imageWithUrl:url placeholderImage:[UIImageConstant defalutBannerPlaceholder] type:ImageTypeUserInfoAlbum complection:^(UIImage * _Nonnull image, NSURL * _Nonnull url) {
@strongify(imageCell);
if (image) {
[imageCell.logoImageView setImageToBlur:image blurRadius:45];

View File

@@ -131,7 +131,7 @@
case XPMineItemType_Account:
{
XPRoomViewController * roomVC = [[XPRoomViewController alloc] init];
roomVC.roomUid = [NSString stringWithFormat:@"%d", 1004437];
roomVC.roomUid = [NSString stringWithFormat:@"%d", 1004587];
BaseNavigationController * baseNav = [[BaseNavigationController alloc] initWithRootViewController:roomVC];
baseNav.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentViewController:baseNav animated:YES completion:nil];

View File

@@ -8,6 +8,14 @@
#import <Foundation/Foundation.h>
#import <NIMSDK/NIMSDK.h>
NS_ASSUME_NONNULL_BEGIN
@class XPRoomMessageDisplayModel;
@protocol RooMessageDelegte <NSObject>
///加载图片完成 一般是第一次加载的时候
- (void)xpRoomMessageDisplayModel:(XPRoomMessageDisplayModel *)displayModel loadImageSuccess:(UIImageView *)imageView;
///点击了某个用户
- (void)xpRoomMessageDisplayModel:(XPRoomMessageDisplayModel *)displayModel didClickUser:(NSString *)userId;
@end
@interface XPRoomMessageDisplayModel : NSObject
///消息实体
@@ -16,8 +24,14 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic,assign, readonly) CGFloat cellHeight;
///所要展示的富文本
@property (nonatomic,strong, readonly) NSMutableAttributedString *contentAttributed;
///选择了某个item
@property (nonatomic,copy) void(^didSelectItem)(NSString * uid);
///加载网络图片成功
@property (nonatomic,copy) void(^loadUrlImage)(UIImageView *imageView);
- (instancetype)initDisplayModel:(NIMMessage *)message;
- (instancetype)initDisplayModel:(NIMMessage *)message delefate:(id<RooMessageDelegte>)delegate;
@end

View File

@@ -12,6 +12,7 @@
#import "XPRoomMessageConstant.h"
#import "AccountInfoStorage.h"
#import "XPRoomMessageAttributeHelper.h"
#import "XPMacro.h"
///Model
#import "XPMessageRemoteExtModel.h"
@@ -22,13 +23,16 @@
@property (nonatomic,assign) CGFloat cellHeight;
///
@property (nonatomic,strong) NSMutableAttributedString *contentAttributed;
///
@property (nonatomic,assign) id<RooMessageDelegte> delegate;
@end
@implementation XPRoomMessageDisplayModel
- (instancetype)initDisplayModel:(NIMMessage *)message {
- (instancetype)initDisplayModel:(NIMMessage *)message delefate:(id<RooMessageDelegte>)delegate {
if (self = [super init]) {
self.message = message;
self.delegate = delegate;
[self makeMessageAttribute:message];
}
return self;
@@ -55,14 +59,27 @@
///
/// @param message
- (void)makeTextAttribute:(NIMMessage *)message {
- (void)makeTextAttribute:(NIMMessage *)message{
NSString * uid = [AccountInfoStorage instance].getUid;
XPMessageRemoteExtModel * model = [XPMessageRemoteExtModel modelWithJSON:message.remoteExt[message.from]];
NSString * nick = [NSString stringWithFormat:@"%@:", ((NIMMessageChatroomExtension *)message.messageExt).roomNickname];
if ([message.from isEqualToString:uid]) {
nick = @"我:";
}
self.contentAttributed = [XPRoomMessageAttributeHelper createLevleTextAttribute:model nick:nick text:message.text];
@kWeakify(self);
self.contentAttributed = [XPRoomMessageAttributeHelper createLevleTextAttribute:model nick:nick text:message.text complection:^(UIImageView * _Nonnull imageView) {
@kStrongify(self);
if (self.delegate && [self.delegate respondsToSelector:@selector(xpRoomMessageDisplayModel:loadImageSuccess:)]) {
[self.delegate xpRoomMessageDisplayModel:self loadImageSuccess:imageView];
}
}];
[self.contentAttributed yy_setTextHighlightRange:NSMakeRange(0, self.contentAttributed.length) color:nil backgroundColor:nil tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
@kStrongify(self);
if (self.delegate && [self.delegate respondsToSelector:@selector(xpRoomMessageDisplayModel:didClickUser:)]) {
[self.delegate xpRoomMessageDisplayModel:self didClickUser:message.from];
}
}];
}
/// tips
@@ -79,7 +96,16 @@
NIMChatroomNotificationMember *member = content.targets[0];
switch (content.eventType) {
case NIMChatroomEventTypeEnter:///
{
self.contentAttributed = [XPRoomMessageAttributeHelper createUserEnterRoomAttribute:member.nick];
@kWeakify(self);
[self.contentAttributed yy_setTextHighlightRange:NSMakeRange(0, self.contentAttributed.length) color:nil backgroundColor:nil tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
@kStrongify(self);
if (self.delegate && [self.delegate respondsToSelector:@selector(xpRoomMessageDisplayModel:didClickUser:)]) {
[self.delegate xpRoomMessageDisplayModel:self didClickUser:member.userId];
}
}];
}
break;
case NIMChatroomEventTypeInfoUpdated:///
[self createRoomInfoUpdateAttribute:content.notifyExt];

View File

@@ -8,13 +8,15 @@
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
typedef void(^AttributeLoadImageComplection)(UIImageView *);
@class XPMessageRemoteExtModel;
@interface XPRoomMessageAttributeHelper : NSObject
#pragma mark - 生成某个消息类型的富文本
/// 文本类的消息的富文本 NIMMessageTypeText
/// @param remoteModel 扩展字段中的内容
/// @param nick 名字
+ (NSMutableAttributedString *)createLevleTextAttribute:(XPMessageRemoteExtModel *)remoteModel nick:(NSString *)nick text:(NSString *)text;
+ (NSMutableAttributedString *)createLevleTextAttribute:(XPMessageRemoteExtModel *)remoteModel nick:(NSString *)nick text:(NSString *)text complection:(nullable AttributeLoadImageComplection)complection;
/// 进入房间的富文本 NIMChatroomEventTypeEnter
/// @param nick 进入房间的名称
@@ -28,8 +30,8 @@ NS_ASSUME_NONNULL_BEGIN
/// 生成一个图片的富文本
/// @param imageUrl 网络图片的地址
/// @param size 网络图片的大小
/// @param success 成功 可以拿到图片的大小刷新富文本的大小
+ (NSMutableAttributedString *)createUrlImageAttribute:(NSString *)imageUrl size:(CGSize)size success:(void(^)(UIImage *))success;
/// @param complection 成功 可以拿到图片的大小刷新富文本的大小
+ (NSMutableAttributedString *)createUrlImageAttribute:(NSString *)imageUrl size:(CGSize)size complection:(nullable AttributeLoadImageComplection)complection;
/// 生成本地一个图片的富文本
/// @param imageName 网络图片的地址

View File

@@ -7,7 +7,8 @@
#import "XPRoomMessageAttributeHelper.h"
///Third
#import "YYText/YYText.h"
#import <YYText/YYText.h>
#import <SDWebImage/SDWebImage.h>
///Tool
#import "UIImageView+LoadImage.h"
///Model
@@ -19,22 +20,33 @@
///
/// @param remoteModel
/// @param nick
+ (NSMutableAttributedString *)createLevleTextAttribute:(XPMessageRemoteExtModel *)remoteModel nick:(NSString *)nick text:(NSString *)text {
+ (NSMutableAttributedString *)createLevleTextAttribute:(XPMessageRemoteExtModel *)remoteModel nick:(NSString *)nick text:(NSString *)text complection:(void (^)(UIImageView *))complection {
NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init];
if (remoteModel.defUser == UserLevelType_Offical) {
NSMutableAttributedString * offcialAttribute = [self createLocalImageAttribute:@"" size:CGSizeMake(13, 13)];
NSMutableAttributedString * offcialAttribute = [self createLocalImageAttribute:@"common_offical" size:CGSizeMake(13, 13)];
[attribute appendAttributedString:offcialAttribute];
[attribute appendAttributedString:[self createSapceAttribute:2]];
}
if (remoteModel.newUser) {
NSMutableAttributedString * newUserAttribute = [self createLocalImageAttribute:@"" size:CGSizeMake(13, 13)];
NSMutableAttributedString * newUserAttribute = [self createLocalImageAttribute:@"common_new_user" size:CGSizeMake(13, 13)];
[attribute appendAttributedString:newUserAttribute];
[attribute appendAttributedString:[self createSapceAttribute:2]];
}
if (remoteModel.experUrl) {
NSMutableAttributedString * experAttribute = [self createUrlImageAttribute:remoteModel.experUrl size:CGSizeMake(34, 13)];
UIImage * image = [self cacheImage:remoteModel.experUrl type:ImageTypeUserIcon];
NSMutableAttributedString * experAttribute;
if (image) {
CGFloat kscale = image.size.width / image.size.height;
experAttribute = [self createImageAttribute:image size:CGSizeMake(20 * kscale, 20)];
} else {
experAttribute = [self createUrlImageAttribute:remoteModel.experUrl size:CGSizeMake(25, 20) complection:^(UIImageView * _Nonnull imageView) {
if (complection) {
complection(imageView);
}
}];
}
[attribute appendAttributedString:experAttribute];
[attribute appendAttributedString:[self createSapceAttribute:2]];
}
@@ -58,6 +70,7 @@
NSMutableAttributedString * enterRoomAttribute = [self createTextAttribute:@"进入了房间" titleColor:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont];
[attribute appendAttributedString:nickAttribute];
[attribute appendAttributedString:enterRoomAttribute];
return attribute;
}
@@ -68,22 +81,24 @@
/// @param imageUrl
/// @param size
+ (NSMutableAttributedString *)createUrlImageAttribute:(NSString *)imageUrl size:(CGSize)size {
return [self createUrlImageAttribute:imageUrl size:size success:nil];
return [self createUrlImageAttribute:imageUrl size:size complection:nil];
}
///
/// @param imageUrl
/// @param size
/// @param success
+ (NSMutableAttributedString *)createUrlImageAttribute:(NSString *)imageUrl size:(CGSize)size success:(void(^)(UIImage *))success {
/// @param complection
+ (NSMutableAttributedString *)createUrlImageAttribute:(NSString *)imageUrl size:(CGSize)size complection:(nullable AttributeLoadImageComplection)complection {
UIImageView *genderImageView = [[UIImageView alloc]init];
[genderImageView load_imageWithUrl:imageUrl placeholderImage:[UIImageConstant defaultAvatarPlaceholder] type:ImageTypeUserIcon success:^(UIImage * _Nonnull image) {
if (image && success) {
success(image);
[genderImageView load_imageWithUrl:imageUrl placeholderImage:[UIImageConstant defaultAvatarPlaceholder] type:ImageTypeUserIcon complection:^(UIImage * _Nonnull image, NSURL * _Nonnull url) {
if (image && complection) {
genderImageView.image = image;
complection(genderImageView);
}
}];
genderImageView.bounds = CGRectMake(0, 0, size.width, size.height);
genderImageView.bounds = CGRectMake(0, 0, 25, 20);
NSMutableAttributedString * genderString = [NSMutableAttributedString yy_attachmentStringWithContent:genderImageView contentMode:UIViewContentModeScaleAspectFit attachmentSize:CGSizeMake(genderImageView.frame.size.width, genderImageView.frame.size.height) alignToFont:[UIFont systemFontOfSize:15.0] alignment:YYTextVerticalAlignmentCenter];
return genderString;
}
@@ -94,7 +109,20 @@
+ (NSMutableAttributedString *)createLocalImageAttribute:(NSString *)imageName size:(CGSize)size {
UIImageView *genderImageView = [[UIImageView alloc]init];
genderImageView.image = [UIImage imageNamed:imageName];
genderImageView.bounds = CGRectMake(0, 0, size.width, size.height);
CGFloat kscale = genderImageView.image.size.width / genderImageView.image.size.height;
genderImageView.bounds = CGRectMake(0, 0, 20 * kscale, 20);
NSMutableAttributedString * genderString = [NSMutableAttributedString yy_attachmentStringWithContent:genderImageView contentMode:UIViewContentModeScaleAspectFit attachmentSize:CGSizeMake(genderImageView.frame.size.width, genderImageView.frame.size.height) alignToFont:[UIFont systemFontOfSize:15.0] alignment:YYTextVerticalAlignmentCenter];
return genderString;
}
///
/// @param image
/// @param size
+ (NSMutableAttributedString *)createImageAttribute:(UIImage *)image size:(CGSize)size {
UIImageView *genderImageView = [[UIImageView alloc]init];
genderImageView.image = image;
CGFloat kscale = genderImageView.image.size.width / genderImageView.image.size.height;
genderImageView.bounds = CGRectMake(0, 0, 20 * kscale,20);
NSMutableAttributedString * genderString = [NSMutableAttributedString yy_attachmentStringWithContent:genderImageView contentMode:UIViewContentModeScaleAspectFit attachmentSize:CGSizeMake(genderImageView.frame.size.width, genderImageView.frame.size.height) alignToFont:[UIFont systemFontOfSize:15.0] alignment:YYTextVerticalAlignmentCenter];
return genderString;
}
@@ -133,4 +161,73 @@
return genderString;
}
+ (UIImage *)cacheImage:(NSString *)urlStr type:(ImageType)type {
NSString * key = [self getCacheImageKey:urlStr type:type];
//
UIImage *image = [[SDImageCache sharedImageCache] imageFromMemoryCacheForKey:key];
//
if (!image) {
image = [[SDImageCache sharedImageCache] imageFromDiskCacheForKey:key];
}
return image;
}
+ (NSString *)getCacheImageKey:(NSString *)imageUrl type:(ImageType)type {
NSMutableString *urlString = [NSMutableString stringWithString:imageUrl];
NSString * configUrl;
switch (type) {
case ImageTypeUserIcon:
{
configUrl = kImageTypeUserIcon;
}
break;
case ImageTypeCornerAvatar:
{
configUrl = kImageTypeCornerAvatar;
}
break;
case ImageTypeRoomFace:
{
configUrl = kImageTypeRoomFace;
}
break;
case ImageTypeUserLibaryDetail:
{
configUrl = kImageTypeUserLibaryDetail;
}
break;
case ImageTypeRoomGift:
{
configUrl = kImageTypeRoomGift;
}
break;
case ImageTypeUserInfoAlbum:
{
configUrl = kImageTypeUserInfoAlbum;
}
break;
default:
break;
}
if (configUrl) {
if ([imageUrl containsString:@"?"]) {
[urlString appendString:@"|"];
}else{
[urlString appendString:@"?"];
}
[urlString appendString:configUrl];
}
NSString *encodedString = (NSString *)
CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
(CFStringRef)urlString,
NULL,
(CFStringRef)@"|",
kCFStringEncodingUTF8));
return encodedString;
}
@end

View File

@@ -8,8 +8,10 @@
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@class XPRoomMessageDisplayModel;;
@class XPRoomMessageDisplayModel, YYLabel;
@interface XPRoomMessageTableViewCell : UITableViewCell
///展示的内容
@property (nonatomic,strong, readonly) YYLabel *contentLabel;
///
@property (nonatomic,strong) XPRoomMessageDisplayModel *displayModel;
@end

View File

@@ -59,6 +59,13 @@
- (void)setDisplayModel:(XPRoomMessageDisplayModel *)displayModel {
_displayModel = displayModel;
self.contentLabel.attributedText = displayModel.contentAttributed;
displayModel.didSelectItem = ^(NSString * _Nonnull uid) {
NSLog(@"你好");
};
displayModel.loadUrlImage = ^(UIImageView * _Nonnull imageView) {
NSLog(@"%@", imageView);
};
}
- (UIImageView *)bubbleImaegeView {

View File

@@ -6,10 +6,12 @@
//
#import <UIKit/UIKit.h>
#import "RoomHostDelegate.h"
NS_ASSUME_NONNULL_BEGIN
@interface XPRoomMessageContainerView : UIView
@interface XPRoomMessageContainerView : UIView<RoomHostDelegate>
- (instancetype)initWithDelegate:(id<RoomHostDelegate>)delegate;
@end

View File

@@ -9,10 +9,14 @@
///Third
#import <Masonry/Masonry.h>
#import <NIMSDK/NIMSDK.h>
#import <YYText/YYText.h>
///Tool
#import "ThemeColor.h"
#import "XPMacro.h"
#import "XPRoomMessageConstant.h"
///Model
#import "XPRoomMessageDisplayModel.h"
#import "RoomInfoModel.h"
///View
#import "XPRoomMessageTableViewCell.h"
#import "XPRoomMessageHeaderView.h"
@@ -21,9 +25,7 @@
#import "XPIMRoomDelegate.h"
#import "XPIMManager.h"
@interface XPRoomMessageContainerView ()<UITableViewDelegate, UITableViewDataSource,XPIMRoomDelegate>
@interface XPRoomMessageContainerView ()<UITableViewDelegate, UITableViewDataSource,NIMChatManagerDelegate, RooMessageDelegte>
///
@property (nonatomic,strong) UITableView *messageTableView;
///
@@ -36,15 +38,18 @@
@property (nonatomic,strong) UIButton *messageTipsBtn;
///
@property (nonatomic,assign) BOOL isPending;
///
@property (nonatomic,weak) id<RoomHostDelegate> hostDelegate;
@end
@implementation XPRoomMessageContainerView
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
- (instancetype)initWithDelegate:(id<RoomHostDelegate>)delegate {
self = [super init];
if (self) {
[[XPIMManager shareManager].chatRoomManager addDelegate:self];
self.hostDelegate = delegate;
[[NIMSDK sharedSDK].chatManager addDelegate:self];
[self initSubViews];
[self initSubViewConstraints];
}
@@ -78,10 +83,18 @@
}];
}
///
- (BOOL)isCurrentRoom:(NSString *)sessionId {
if ([sessionId isEqualToString:[NSString stringWithFormat:@"%ld", self.hostDelegate.getRoomInfo.roomId]]) {
return YES;
}
return NO;
}
#pragma mark -
///
- (void)addRoomMessage:(NIMMessage *)message {
XPRoomMessageDisplayModel * model = [[XPRoomMessageDisplayModel alloc] initDisplayModel:message];
XPRoomMessageDisplayModel * model = [[XPRoomMessageDisplayModel alloc] initDisplayModel:message delefate:self];
[self.tempArray addObject:model];
///
[self tryToappendAndScrollToBottom];
@@ -134,6 +147,29 @@
[self.messageTableView scrollToRowAtIndexPath:ip atScrollPosition:UITableViewScrollPositionNone animated:animated]; //
}
#pragma mark - NIMChatManagerDelegate
- (void)onRecvMessages:(NSArray<NIMMessage *> *)messages {
for (NIMMessage * message in messages) {
///
if (message.session.sessionType == NIMSessionTypeChatroom && [self isCurrentRoom:message.session.sessionId]) {
if (message.messageType == NIMMessageTypeText || message.messageType == NIMMessageTypeTip) {
[self addRoomMessage:message];
} else if (message.messageType == NIMMessageTypeNotification) {
NIMNotificationObject *notiMsg = (NIMNotificationObject *)message.messageObject;
NIMChatroomNotificationContent *content = (NIMChatroomNotificationContent *)notiMsg.content;
if (content.eventType == NIMChatroomEventTypeEnter) {
[self addRoomMessage:message];
}
}else if (message.messageType == NIMMessageTypeCustom) {//
///TODO :
}
} else {
}
}
}
#pragma mark - ScrollViewDelegate
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
//
@@ -182,6 +218,40 @@
}
- (void)xpRoomMessageDisplayModel:(XPRoomMessageDisplayModel *)displayModel loadImageSuccess:(UIImageView *)imageView {
NSInteger index = [self.datasource indexOfObject:displayModel];
XPRoomMessageTableViewCell * cell = [self.messageTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:index inSection:0]];
[self loadUrlImageSuccess:imageView cell:cell];
}
- (void)xpRoomMessageDisplayModel:(XPRoomMessageDisplayModel *)displayModel didClickUser:(NSString *)userId {
NSLog(@"点击的用户%@", userId);
}
- (void)loadUrlImageSuccess:(UIImageView *)imageView cell:(XPRoomMessageTableViewCell *)cell {
CGSize size = CGSizeMake(kRoomMessageMaxWidth, CGFLOAT_MAX);
YYTextLayout *layout = [YYTextLayout layoutWithContainerSize:size text:cell.contentLabel.attributedText];
NSMutableAttributedString * attribute = [cell.contentLabel.attributedText mutableCopy];
if (layout.attachments.count > 0) {
for (int i = 0; i < layout.attachments.count; i++) {
YYTextAttachment * attachment = [layout.attachments objectAtIndex:i];
if (imageView == attachment.content) {
CGFloat kscale = (CGFloat)imageView.image.size.width / (CGFloat)imageView.image.size.height;
imageView.frame = CGRectMake(0, 0, 40 * kscale, 40);
attachment.content = imageView;
NSValue * value = [layout.attachmentRanges objectAtIndex:i];
NSRange range = value.rangeValue;
NSMutableAttributedString * resultString = [NSMutableAttributedString yy_attachmentStringWithContent:imageView contentMode:UIViewContentModeScaleAspectFit attachmentSize:imageView.image.size alignToFont:[UIFont systemFontOfSize:14.0] alignment:YYTextVerticalAlignmentCenter];
[attribute replaceCharactersInRange:range withAttributedString:resultString];
break;
}
}
cell.contentLabel.attributedText = nil;
cell.contentLabel.attributedText = attribute;
}
}
#pragma mark - Getters And Setters
- (UITableView *)messageTableView {
if (!_messageTableView) {

View File

@@ -45,7 +45,7 @@
///
@property (nonatomic,strong) UIButton *settingButton;
@property (nonatomic, strong) id<RoomHostDelegate> hostDelegate;
@property (nonatomic, weak) id<RoomHostDelegate> hostDelegate;
@end

View File

@@ -32,7 +32,7 @@
@property (nonatomic, strong) NSMutableArray *microViews;
@property (nonatomic, strong) NSMutableDictionary<NSString *, MicroQueueModel *> *micQueue;
@property (nonatomic, strong) id<RoomHostDelegate> hostDelegate;
@property (nonatomic, weak) id<RoomHostDelegate> hostDelegate;
@end

View File

@@ -56,7 +56,7 @@
- (void)dealloc {
#warning to do -
#warning to dox -
}
@@ -70,7 +70,6 @@
- (void)viewDidLoad {
[super viewDidLoad];
[self addDelegate];
[self initSubViews];
[self initSubViewConstraints];
}
@@ -82,10 +81,6 @@
#pragma mark - Private Method
- (void)addDelegate {
[[XPIMManager shareManager].chatRoomManager addDelegate:self];
}
- (void)initSubViews {
[self.view addSubview:self.backContainerView];
[self.view addSubview:self.roomHeaderView];
@@ -211,7 +206,7 @@
- (XPRoomMessageContainerView *)messageContainerView {
if (!_messageContainerView) {
_messageContainerView = [[XPRoomMessageContainerView alloc] init];
_messageContainerView = [[XPRoomMessageContainerView alloc] initWithDelegate:self];
}
return _messageContainerView;
}