2、键盘消失
- (void)keyboardWillHide:(NSNotification *)notification {
//如果是弹出了底部视图时
if (self.moreClick || self.emojiClick) {
return;
}
[UIView animateWithDuration:0.25 animations:^{
self.frame = CGRectMake(0, K_Height - StatusNav_Height - self.backView.height, K_Width, self.backView.height);
[self changeTableViewFrame];
}];
}
3、点击更多按钮
- (void)moreBtn:(UIButton *)btn {
self.emojiClick = NO; //主要是设置表情按钮为未点击状态
if (self.moreClick == NO) {
self.moreClick = YES;
//回收键盘
[self.textView resignFirstResponder];
[self.emojiView removeFromSuperview];
self.emojiView = nil;
[self addSubview:self.moreView];
//改变更多、self的frame
[UIView animateWithDuration:0.25 animations:^{
self.moreView.frame = CGRectMake(0, self.backView.height, K_Width, bottomHeight);
self.frame = CGRectMake(0, K_Height - StatusNav_Height - self.backView.height - bottomHeight, K_Width, self.backView.height + bottomHeight);
[self changeTableViewFrame];
}];
} else { //再次点击更多按钮
//键盘弹起
[self.textView becomeFirstResponder];
}
}
4、改变输入框大小
- (void)changeFrame:(CGFloat)height {
CGRect frame = self.textView.frame;
frame.size.height = height;
self.textView.frame = frame; //改变输入框的frame
//当输入框大小改变时,改变backView的frame
self.backView.frame = CGRectMake(0, 0, K_Width, height + (viewMargin * 2));
self.frame = CGRectMake(0, K_Height - self.backView.height - self.keyboardHeight, K_Width, self.backView.height);
//改变更多按钮、表情按钮的位置
self.emojiBtn.frame = CGRectMake(viewMargin, self.backView.height - viewHeight - viewMargin, viewHeight, viewHeight);
self.moreBtn.frame = CGRectMake(self.textView.maxX + viewMargin, self.backView.height - viewHeight - viewMargin, viewHeight, viewHeight);
//主要是为了改变VC的view的frame
if (self.delegate && [self.delegate respondsToSelector:@selector(changeFrameWithMinY:)]) {
[self.delegate changeFrameWithMinY:self.minY];
}
}
以上就是聊天输入框的简单实现,只是提供一个实现思路,如果在聊天界面中接入,还需要处理以下问题:
1、demo中没有做tableViewCell的高度自适应;
2、输入框文案较多时,tableViewCell可能会出现紊乱,此处没有处理
demo中如果有任何问题,欢迎各位留言拍砖,小弟一定更正,共同学习;
GitHub地址
总结
以上所述是小编给大家介绍的iOS实现聊天输入框功能,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对ASPKU网站的支持!
注:相关教程知识阅读请移步到IOS开发频道。










