IOS键盘遮盖问题解决办法
来源:互联网 发布:JAVA年龄正则表达式 编辑:程序博客网 时间:2024/06/14 13:50
1.添加键盘显示和隐藏通知事件响应
<pre name="code" class="objc"> // 添加键盘显示/隐藏的通知 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardDidShowNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
2.事件响应
<pre name="code" class="objc">#pragma mark - Notification Method///键盘显示事件- (void) keyboardWillShow:(NSNotification *)notification { //获取键盘高度,在不同设备上,以及中英文下是不同的 CGFloat kbHeight = [[notification.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size.height; // 取得键盘的动画时间,这样可以在视图上移的时候更连贯 double duration = [[notification.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue]; CGFloat offset=输入框下边沿纵坐标-(self.view.frame.size.height-kbHeight); //将视图上移计算好的偏移 if(offset > 0) { [UIView animateWithDuration:duration animations:^{ self.view.frame = CGRectMake(0.0f, -offset, self.view.frame.size.width, self.view.frame.size.height); }]; }}///键盘消失事件- (void) keyboardWillHide:(NSNotification *)notify { // 键盘动画时间 double duration = [[notify.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue]; //视图下沉恢复原状 [UIView animateWithDuration:duration animations:^{ self.view.frame = CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height); }];}
0 0
- IOS键盘遮盖问题解决办法
- ios 键盘遮盖
- IOS UITextField输入 键盘遮盖
- 键盘遮挡问题解决办法
- React Native 键盘管理和 Tab Navigator 在Android TextInput遮盖,Tab Navigator上移等问题解决办法
- ios 键盘遮盖TextField的解决方法
- MFC中使用SetWindowPos GroupBox遮盖内部控件问题解决办法
- android 虚拟机键盘无法使用问题解决办法
- Flex与Google Iframe弹出框被Iframe遮盖问题解决办法
- Flex与Google Iframe弹出框被Iframe遮盖问题解决办法
- 键盘遮盖问题
- frameset 将截断键盘和鼠标事件的问题解决办法
- android键盘和界面挤压的问题解决办法
- iOS常见异常Exec_Bad_Access问题解决办法
- 关于iOS上图图片压缩问题解决办法
- PHP 极光推送 ios-dev 问题解决办法
- iOS上滑动不流畅问题解决办法
- iOS 键盘遮挡处理办法(不用键盘高度计算)
- PHP学习:数组的转化
- epel 下载地址
- 华为路由器 端口映射与防火墙
- 字符集编码浅谈:Unicode、UTF-8
- Android 动画应用完全解析(一)
- IOS键盘遮盖问题解决办法
- 编写好代码的几个要素
- 进程通信概述
- 【Zanuck 镇】编写php高性能snowflake算法插件(分布式64位唯一性自增id生成算法)
- 删数问题
- apache的DBUtil框架学习
- ContentProvide之手机联系人
- poj 3685(二分查找第K大的值)
- Leetcode 389 Find the Difference