打开键盘遮住View的问题解决方法-IOS开发
2016-05-12 11:14
781 查看
5.0 以后键盘的高度貌似不是216了,不过不要紧,我们调整调整就是了:
我们采取的方法就是在textField(有可能是其他控件)接收到弹出键盘事件时把self.view整体上移216px了(我们就以iPhone竖屏为例了)。有关View的frame,origin,size之类的知识点不懂的请参看我的另一篇博文: <<有关View的几个基础知识点>>首先我们要设置textField的代理,我们就设为当前控制器了。textField,delegate=self;然后我们在当前控制器实现下面三个委托方法:
[java] view plain copy
print?
- (void)textFieldDidBeginEditing:(UITextField *)textField
{ //当点触textField内部,开始编辑都会调用这个方法。textField将成为first responder
NSTimeInterval animationDuration = 0.30f;
CGRect frame = self.view.frame;
frame.origin.y -=216;
frame.size.height +=216;
self.view.frame = frame;
[UIView beginAnimations:@"ResizeView" context:nil];
[UIView setAnimationDuration:animationDuration];
self.view.frame = frame;
[UIView commitAnimations];
}
[java] view plain copy
print?
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{//当用户按下ruturn,把焦点从textField移开那么键盘就会消失了
NSTimeInterval animationDuration = 0.30f;
CGRect frame = self.view.frame;
frame.origin.y +=216;
frame.size. height -=216;
self.view.frame = frame;
//self.view移回原位置
[UIView beginAnimations:@"ResizeView" context:nil];
[UIView setAnimationDuration:animationDuration];
self.view.frame = frame;
[UIView commitAnimations];
[textField resignFirstResponder];
}
iPhone | ipad | |
竖屏(portrait) | 216 | 264 |
横屏(landScape) | 140 | 352 |
[java] view plain copy
print?
- (void)textFieldDidBeginEditing:(UITextField *)textField
{ //当点触textField内部,开始编辑都会调用这个方法。textField将成为first responder
NSTimeInterval animationDuration = 0.30f;
CGRect frame = self.view.frame;
frame.origin.y -=216;
frame.size.height +=216;
self.view.frame = frame;
[UIView beginAnimations:@"ResizeView" context:nil];
[UIView setAnimationDuration:animationDuration];
self.view.frame = frame;
[UIView commitAnimations];
}
[java] view plain copy
print?
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{//当用户按下ruturn,把焦点从textField移开那么键盘就会消失了
NSTimeInterval animationDuration = 0.30f;
CGRect frame = self.view.frame;
frame.origin.y +=216;
frame.size. height -=216;
self.view.frame = frame;
//self.view移回原位置
[UIView beginAnimations:@"ResizeView" context:nil];
[UIView setAnimationDuration:animationDuration];
self.view.frame = frame;
[UIView commitAnimations];
[textField resignFirstResponder];
}
相关文章推荐
- 绝大部分 Android 手电筒应用需要大量权限
- 这些看似合法的 iPhone Lightning 数据线将劫持您的电脑
- 每日安全资讯:NSO,一家专业入侵 iPhone 的神秘公司
- 我的iPhone桌面
- Lua中关于元方法的一些知识点小结
- ThinkPHP控制器详解
- ASP.NET MVC4入门教程(五):从控制器访问数据模型
- ASP.NET MVC4入门教程(二):添加一个控制器
- 三种检测iPhone/iPad设备方向的方法
- js实现iPhone界面风格的单选框和复选框按钮实例
- jQuery常用知识点总结以及平时封装常用函数
- jQuery知识点整理
- PHP容易忘记的知识点分享
- ASP.NET Web API教程 创建Admin控制器实例分享
- C# 如何在MVC3中取消备用控制器的选择
- ThinkPHP控制器里javascript代码不能执行的解决方法
- PHP易混淆知识整理笔记
- 初识ThinkPHP控制器