【iOS开发】封装聊天输入框MKInputBar,语音支持iOS & Android平台

  最近做的一个项目,有聊天的功能,最开始从网上找了个被人封装好的输入框,写的很复杂(反正我有点被看迷糊了),用起来呢又有点问题,最终放弃,自己封装了一个聊天输入框MKInputBar,难度不大。语音支持iOS和Android平台,其实就是把caf转换为mp3。底部给出了Demo工程,用起来很简单。


先上几张图吧

   

   

用法很简答,封装好只有两个文件MKInputBar.h & MKInputBar.m,实现三个代理方法:

1 - (void)inputBar:(MKInputBar *)inputBar didSendText:(NSString *)text;
2 - (void)inputBar:(MKInputBar *)inputBar didSendVoice:(NSString *)voicePath; 
3 - (void)inputBar:(MKInputBar *)inputBar didTakeImageWithSourceType:(UIImagePickerControllerSourceType)sourceType;

有几点需要说明:

1、在ViewContrller.m中,监听键盘的UIKeyboardWillShowNotification和UIKeyboardWillHideNotification调整inputBar的位置,然后通过KVO监听inputBar的frame来动态调整消息显示msgTableView的frame。

2、Demo中libmp3lame.a链接库不支持arm64指令集,需在Target中Build Settings中的Valid Architectures中将armv64删除。同时,置Build Active Architecture Only(Debug & Release)为NO。

Demo链接在此

 Download ZIP

原文地址:https://www.cnblogs.com/youthpasses/p/3880102.html