iOS移动开发中监听键盘移动的事件,自动调整view-(1)-UIKeyboardFrameEndUserInfoKey
来源:互联网 发布:阿里云域名可以转让吗 编辑:程序博客网 时间:2024/05/16 07:36
UIKeyboardFrameEndUserInfoKey 是监听键盘的移动的时间,比如说键盘推出、键盘回收。
可在iOS程序中通过C语言私有的内联函数实现
//通过监听键盘的动作,得到键盘的高度
static inline CGFloat getKeyboardHeight(NSNotification *notify) {
CGRect kbSize = [[notify.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];return kbSize.size.height;
}
(static 私有 inline内联函数===》内联函数相当于define,在函数中调用的时间,直接复制获取,减少了调用的时间提高了效率)
//键盘将要显示时候
- (void) keyboardWillShow:(NSNotification *)notify {
UIView *sv = focusTextField.superview;
CGFloat kbHeight = getKeyboardHeight(notify);
// 取得键盘的动画时间
double duration = [[notify.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
CGFloat screenHeight = self.view.bounds.size.height;
CGFloat viewBottom = sv.frame.origin.y + sv.frame.size.height;
if (viewBottom + kbHeight < screenHeight) return;
// 键盘会盖住输入框, 要移动整个view了
delta = viewBottom + kbHeight - screenHeight + 50;
// masonry的地方了 mas_updateConstraints 更新superView的约束(masonry是自动布局的三方库,可参考github)
[superView mas_updateConstraints:^(MASConstraintMaker *make) {
//调整上面的偏移量
make.top.equalTo(self.view.mas_top).offset(-delta);
}];
[UIView animateWithDuration:duration animations:^void(void){
// superView来重新布局
[superView layoutIfNeeded];
}];
}
//键盘将要隐藏的时候
- (void) keyboardWillHidden:(NSNotification *)notify {
// 键盘动画时间
double duration = [[notify.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
[superView mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.view.mas_top);
}];
[UIView animateWithDuration:duration animations:^{
[superView layoutIfNeeded];
}];
delta = 0.0f;
}
- iOS移动开发中监听键盘移动的事件,自动调整view-(1)-UIKeyboardFrameEndUserInfoKey
- iOS开发监听键盘(添加键盘和隐藏键盘,改变视图中整体控件随着键盘的高度移动)
- 键盘事件的监听-控制飞机移动
- ios 键盘遮挡,监听键盘调整view的frame
- cocos TextField + ios键盘 状态监听 移动view
- IOS开发键盘上方的view随着键盘的弹出、收起、键盘输入法改变而移动
- ios捕捉移动view的点击事件
- 【iOS开发】跟踪键盘的移动
- iOS移动View点击事件
- (二十四)监听键盘的通知和键盘弹出隐藏的View移动
- 移动view的点击事件
- 动态监听键盘高度,并进行view的移动(防止遮住textField)
- iOS移动View点击事件(二)
- 键盘事件移动元素
- iOS之旅--Swift3中UIKeyboardFrameEndUserInfoKey的用法
- 混合开发中手机键盘监听事件的问题
- iOS-通过键盘的监听完成底部工具条的黏性移动
- iOS 开发中移动collectionView的item
- iOS音频播放 (八):NowPlayingCenter和RemoteControl
- 关于navicat连接oracle报错ORA-28547
- [笔记]Android中在外部编译kernel module示例
- hadoop配置
- Intents and Intent Filters
- iOS移动开发中监听键盘移动的事件,自动调整view-(1)-UIKeyboardFrameEndUserInfoKey
- linux统计文件中字符串出现次数
- Linux定时器实现
- javascript的引用类型
- Android开发问题汇总
- internet explore遇到常见问题
- [转载]编程入门指南
- Activities
- 使用pushmebaby测试app的远程推送功能