开发笔记——检测键盘的弹出与消失
来源:互联网 发布:java架构师工作 编辑:程序博客网 时间:2024/05/17 05:50
iOS开发中经常遇到要检测键盘的高度并做相应的偏移动画的场景,再次仅做记录,在需要的时候直接copy即可
1.添加监听:(一般情况下只需监听键盘将要弹出和将要隐藏的方法即可)
/* UIKeyboardWillChangeFrameNotification键盘的frame将要发生改变时发出的通知(位置和尺寸) UIKeyboardDidChangeFrameNotification键盘的frame发生改变时发出的通知(位置和尺寸) UIKeyboardWillShowNotification键盘将要弹出 UIKeyboardDidShowNotification键盘弹出时 UIKeyboardWillHideNotification键盘将要隐藏 UIKeyboardDidHideNotification键盘已经隐藏 */ //监听键盘将要弹出 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; //增加监听,当键退出时收出消息 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
2.添加监听方法:
3.在delloc方法中移除监听//键盘将要弹出-(void)keyboardWillShow:(NSNotification *)sender{ //获取键盘的高度 NSDictionary *userInfo = [sender userInfo]; NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey]; CGRect keyboardRect = [aValue CGRectValue]; CGFloat height = keyboardRect.size.height; }//键盘将要隐藏-(void)keyboardWillHide:(NSNotification *)sender{ }
//移除监听-(void)dealloc{ [[NSNotificationCenter defaultCenter] removeObserver:UIKeyboardWillShowNotification]; [[NSNotificationCenter defaultCenter] removeObserver:UIKeyboardWillHideNotification];}
0 0
- 开发笔记——检测键盘的弹出与消失
- 监听键盘的弹出与消失
- 键盘的弹出与消失(通知)
- 监听键盘的弹出与消失
- iOS键盘弹出又消失的问题
- 检测键盘的出现跟消失
- 监听键盘弹出和消失
- 如何让 UITextField弹出的键盘 消失disappear
- 键盘弹出和消失View的上下移动效果
- iOS开发- 自动消失的弹出框
- iOS开发- 自动消失的弹出框
- iOS开发-自动消失的弹出框
- 软键盘弹出与消失的方法
- 弹出输入法键盘,标题栏上移消失问题解决
- 键盘消失的操作方法
- iOS开发之UI——键盘弹出屏幕上移
- iOS开发键盘的弹出风格设置
- iOS输入框UITextView随键盘UIkeyboard弹出与消失改变Rect
- POJ 2288 Islands and Bridges
- JS实现密码加密
- HTTP协议详解
- Android TextView实现跑马灯效果
- Linux 命令(文件和目录管理 - more/less)
- 开发笔记——检测键盘的弹出与消失
- 谷歌电子市场第4天总结
- [Android Studio 插件] AndroidPixelDimenGenerator 自动生成多种分辨率dimen文件
- 虚拟机和主机之间ping不通/开发板和虚拟机之间ping不通
- You need to run build with JDK or have tools.jar on the classpath.
- 2016/10/19
- HBase JAVA API 开发
- yii xss简单攻击
- Dlib人脸关键点检测顺序