CDChatList 介绍
CDChatList
高性能的聊天页面解决方案 对聊天列表的高度封装,可灵活配置页面样式
聊天界面其实大同小异,所以这里封装了一个聊天的组件,使用CoreText和手动代码布局,尽量实现简单,通用,高效,易于维护。
项目结构
CDChatListView: UITableView 视图,聊天页面主体
CDBaseMsgCell: 实现消息气泡基本视图
CDTextTableViewCell、CDImageTableViewCell、CDAudioTableViewCell:
继承自CDBaseMsgCell,实现响应功能。 CDSystemTableViewCell: 特殊消息气泡,实现系统通知
CellCaculator: tableview布局计算,并提前渲染cell
ChatConfiguration: chatlist配置类组,UI定制,及资源等
CDLabel: 富文本标签 CDChatInputBox: 输入框封装组件
安装
支持至iOS 11
pod 'CDChatList' #import <CDChatList/CDChatList.h>
使用
ChatHelpr负责ChatHelpr的UI配置,及组件的资源文件设置
UI配置及资源文件都有默认,所以无需自定义的话,就可以跳过组件的配置
添加 CDChatList 视图
CDChatListView *list = [[CDChatListView alloc] initWithFrame:self.view.bounds]; list.msgDelegate = self;self.listView = list; [self.view addSubview:self.listView];
CDChatList会将视图控制器automaticallyAdjustsScrollViewInsets及contentInsetAdjustmentBehavior设为NO及Never,并适应导航栏高度
消息模型 MessageModalProtocal
可以使用自己的消息模型,消息模型需遵守MessageModalProtocal,实现相关属性
组件事件 ChatListProtocol
消息列表请求加载更多消息
-(void)chatlistLoadMoreMsg: (CDChatMessage)topMessage callback: (void(^)(CDChatMessageArray))finnished;
消息中的点击事件
-(void)chatlistClickMsgEvent: (ChatListInfo *)listInfo;
-(void)addMessagesToBottom: (CDChatMessageArray)newBottomMsgArr;
更新数据源中的某条消息模型(主要是为了更新UI上的消息状态)
-(void)updateMessage:(CDChatMessage)message;
使用场景
// 发{ MessageModal *modal; } -(void)send{ modal = [[MessageModal alloc] init]; modal.msgState = CDMessageStateSending; modal.createTime = ...; modal.msg = ...; modal.msgType = ...; [chatList addMessagesToBottom: modal]; } -(void)sendCallBack:(BOOL)isSuccess{ modal.msgState = isSuccess; // 此处应处理成枚举 [chatList updateMessage: modal]; }// 收-(void)receivednewMessage:(MessageModal *)modal{ [chatList addMessagesToBottom: modal]; }
消息列表被下拉时,触发此回调
-(void)chatlistLoadMoreMsg: (CDChatMessage)topMessage callback: (void(^)(CDChatMessageArray))finnished { // 根据topMessage 获取更多消息 NSArray *msgArr = [self getMoreMessageFrom: topMessage amount: 10]; callback(msgArr); }
目前消息体重处理了 文本点击 及 图片点击 事件
-(void)chatlistClickMsgEvent: (ChatListInfo *)listInfo{ if (listInfo.eventType == ChatClickEventTypeTEXT){ // 点击的文本 listInfo.clickedText // 点击的文字位置 防止有相同的可点击文字 listInfo.range // 被点击文本的隐藏信息 e.g. <a title=转人工 href=doTransfer> listInfo.clickedTextContent } else if (listInfo.eventType == ChatClickEventTypeIMAGE){ // 图片 listInfo.image // 图片在tableview中的位置 listInfo.msgimageRectInTableView } }
Todo
CDChatList 官网
https://github.com/chdo002/CDChatList
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。