iOS 即时聊天键盘处理
1 让tableview 滚动到最底层方法
if (_dataArr.count>0) {
NSIndexPath *ip = [NSIndexPath indexPathForRow:_dataArr.count-1 inSection:0];
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView scrollToRowAtIndexPath:ip atScrollPosition:UITableViewScrollPositionBottom animated:YES];
});
}
2了解scrollview一个方法,用手指滑动才会执行的方法
-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
3每次聊天要在最下面加一条数据 使用到的方法(不能用刷新方法加最后一条 得插入)
NSInteger index = self.dataArr.count-1;
NSIndexPath *indexPath=[NSIndexPath indexPathForRow:index inSection:0];
[_tableView insertRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
4 刷新某一条cell方法
NSIndexPath *indexPath=[NSIndexPath indexPathForRow:index inSection:0];
[_tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
5 获取当前tableview 内容高度 有几种方法
(1)获取section的frame
- (CGRect)rectForSection:(NSInteger)section;
(2)获取cell的frame
- (CGRect)rectForRowAtIndexPath:(NSIndexPath *)indexPath;
(3)获取header的frame
- (CGRect)rectForHeaderInSection:(NSInteger)section;
(4)获取footer的frame
- (CGRect)rectForFooterInSection:(NSInteger)section;
***********这里边 我们需求只有一个section 写一个footer 来获取整个当前tableview内容高度
CGRect rectCell = [_tableView rectForFooterInSection:0];
当前内容高度为:rectCell.origin.y
6 以上五部结合一下 弹键盘,适用场景,打一次字,发出去收键盘 ,要是想持续打字键盘不收回去,还需要优化一下下面的方法
- (void)keyboardWillShow:(NSNotification *)notification {
CGRect rect=[notification.userInfo[UIKeyboardFrameEndUserInfoKey]CGRectValue];
WS(weakSelf)
[self.bottomView mas_updateConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(self.view).offset(-rect.size.height);
}];
if (Height(85)+rect.size.height +weakSelf.contentHeight>kScreenHeight) {
if (weakSelf.contentHeight>kScreenHeight-Height(85)-45) {
[UIView animateWithDuration:0.25 animations:^{
CGRect frame = weakSelf.tableView.frame;
frame.origin.y = - (rect.size.height)+Height(85);
weakSelf.tableView.frame = frame;
}];
[UIView animateWithDuration:0.25 animations:^{
[weakSelf.tableView refreshCurrentTableViewContengHeight];
}];
}else{
[UIView animateWithDuration:0.25 animations:^{
CGRect frame = weakSelf.tableView.frame;
frame.origin.y = - ( Height(85)+rect.size.height +weakSelf.contentHeight)+(kScreenHeight-Height(85))+Height(85)+45;
weakSelf.tableView.frame = frame;
}];
[UIView animateWithDuration:0.25 animations:^{
[weakSelf.tableView refreshCurrentTableViewContengHeight];
}];
}
}
}
- (void)keyboardWillHide:(NSNotification *)notification {
CGFloat tabbarHeight = Height_TabbarSafeBottom;
WS(weakSelf)
[self.bottomView mas_updateConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(self.view).offset(-tabbarHeight);
}];
[UIView animateWithDuration:0.25 animations:^{
CGRect frame = weakSelf.tableView.frame;
frame.origin.y = Height(85);
weakSelf.tableView.frame = frame;
}];
}
iOS 即时聊天键盘处理相关推荐
- ios 即时聊天轻松搞定
使用技术: CocoaAsyncSocket + Apache MINA(ApacheMINA是一个网络应用程序框架,用来帮助用户简单地开发高性能和高可扩展性的网络应用程序.它提供了一个通过Java ...
- iOS 即时聊天 音频格式转NSData
WAV:无损 是微软公司开发的一种声音文件格式,它符合PIFFResource Interchange File Format文件规范,用于保存WINDOWS平台的音频信息资源,被WINDOWS平台及 ...
- 基于WebSocket协议的iOS端即时聊天
好好好久没有在cnblogs上写博客,不过在这里写的最早的一篇博客的时间戳,真是时间久远啊,那时候还没毕业.不在cnblogs的期间,在github pages.简书上写过博客,github page ...
- iOS即时语音聊天技术实践
CMDN Club第十五期活动已于3月15日顺利举行,本次活动以"移动平台语音技术的应用与实践"主题,以语音技术开发为焦点,从语音基础服务.语音产品开发.语音技术实现等多个维度,探 ...
- ios开发xmpp仿微信即时聊天工具
最近在做一个项目,需要一个即时聊天工具,先打算有第三方环信(http://www.easemob.com),但是最终老板不允许,要自己开发用自己的服务器,哎!如果有需要的可以去看看这个环信,真的不错. ...
- iOS开源组件__仿写QQ/微信聊天键盘(表情,问题,输入框)纯代码,无依赖
前言 1.由于项目需求,需要一个类似QQ/微信的聊天键盘,包括语音,emoji和发送图片,文件,位置,网上找了一番,要不功能不够完善,要不依赖太多,于是干脆自己写一个(在使用过程中如果发现什么问题或有 ...
- iOS即时通讯输入框随字数自适应高度
代码地址如下: http://www.demodashi.com/demo/13210.html 前言 本人最近在研究socket与聊天界面的UI,在写聊天界面UI的时候是模仿微信的界面其中的文字输入 ...
- iOS即时通讯,从入门到“放弃”?
image 前言 本文会用实例的方式,将iOS各种IM的方案都简单的实现一遍.并且提供一些选型.实现细节以及优化的建议. 注:文中的所有的代码示例,在github中都有demo: iOS即时通讯,从入 ...
- iOS即时通讯从入门到“放弃”?
前言 本文会用实例的方式,将iOS各种IM的方案都简单的实现一遍.并且提供一些选型.实现细节以及优化的建议. 注:文中的所有的代码示例,在github中都有demo: iOS即时通讯,从入门到&quo ...
最新文章
- 【Sql Server】DateBase-触发器
- 服务器混合硬盘安装linux,UBUNTU下如何开启SSHD服务
- 那些年Android黑科技①:只要活着,就有希望
- 最优化——线性规划总结1(线性规划标准型,规范型,顶点)
- GDCM:gdcm::IODs的测试程序
- 让电影票房飞一会儿,五一换个姿势重温经典
- 软件_linux命令cp目录路径和通配符
- java判断那个时间更晚_如何用Java判断日期是早于还是晚于另一个日期
- Xcode给应用开启沙箱sandbox
- bea tuxedo中间件入门
- 《现代控制系统》第四章——反馈控制系统特性 4.3 控制系统对参数变化的敏感程度
- spring Clound EMERGENCY! EUREKA MAY BE INCORRECTLY CLAIMING INSTANCES ARE UP WHEN THEY'RE NOT. RENEW
- java 整数相除 小数点_java整数相除保留小数
- 什么是soft wrap,什么是IDEA的soft wrap,如何设置IDEA默认所有类型的文件都自动换行(如何设置用IDEA打开markdown文件不自动换行)
- 场景中配置阴影(个人笔记)
- 华为路由器默认用户名密码
- 解决VMware安装Ubuntu20.04没有中文输入法
- 【C/C++】排序讲解,C语言实现各种排序
- 博弈论 思路及模板代码
- RouterOS(ROS)定时备份配置并发送至邮箱脚本