通知监听键盘的出现和隐藏,让工具条紧贴着键盘

http://www.cnblogs.com/zhanghuanan/p/5611675.html

//注册一个通知

[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];

//通知方法

-(void)keyboardWillChangeFrame:(NSNotification*)note

{

// 、显示或隐藏键盘时的高度

CGRect frame = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];

//修改底部约束(需要改变的控件位置)

self.bottomSapce.constant=UIHight-frame.origin.y;

//动画时间

CGFloat duration=[note.userInfo[UIKeyboardAnimationDurationUserInfoKey]doubleValue];

[UIView animateWithDuration:duration animations:^{

[self.view layoutIfNeeded];//改变控制的位置

}];

}

-(void)dealloc

{//取消通知。控制器消失时需要移除通知

[[NSNotificationCenter defaultCenter]removeObserver:self];

}

效果如下图:原来在底部的输入工具条,当键盘弹出时,上移一定高度,让工具条紧贴着键盘。



最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容