InputToolbar:键盘工具条
VoiceButtonView:语音模块视图
EmojiButtonView:Emoji模块视图
MoreButtonView:加号模块视图(相册,相机,文件,位置...)
CollectionViewFlowLayout:表情键盘CollectionView布局
EmpjiCollectionViewCell:表情键盘collectionViewCell
UIView+Extension:UIView工具类
加头文件:
#import "InputToolbar.h"
遵守协议
<MoreButtonViewDelegate>
添加属性:
@property (nonatomic,strong)InputToolbar *inputToolbar;
创建inputToolbar
self.inputToolbar = [InputToolbar shareInstance];
[self.view addSubview:self.inputToolbar];
输入框最大显示行数
self.inputToolbar.textViewMaxVisibleLine = 4;
布局inputToolbar
self.inputToolbar.width = self.view.width;
self.inputToolbar.height = 49;
self.inputToolbar.y = self.view.height - self.inputToolbar.height;
设定代理
[self.inputToolbar setMorebuttonViewDelegate:self];
点击发送按钮回调,顺便传回输入内容
__weak typeof(self) weakSelf = self;
self.inputToolbar.sendContent = ^(NSObject *content){
NSLog(@"发射成功☀️:---%@",content);
if ([content isKindOfClass:[NSTextAttachment class]]) {
[weakSelf.textView.textStorage insertAttributedString:[NSAttributedString attributedStringWithAttachment:(NSTextAttachment *)content] atIndex:weakSelf.textView.selectedRange.location];
} else {
weakSelf.textView.text = ((NSAttributedString *)content).string;
}
};
self.inputToolbar.inputToolbarFrameChange = ^(CGFloat height,CGFloat orignY){
_inputToolbarY = orignY;
};
//点击MoreButtonView中的按钮会调用此方法(根据实际需求自行增删)
- (void)moreButtonView:(MoreButtonView *)moreButtonView didClickButton:(MoreButtonViewButtonType)buttonType
{
switch (buttonType) {
case MoreButtonViewButtonTypeImages:
{
//发送相册操作
} break;
case MoreButtonViewButtonTypeCamera:
{
//发送相机操作
} break;
case MoreButtonViewButtonTypeFile:
{
//发送文件操作
} break;
//.........
default:
break;
}
}