5.0 以后键盘的高度貌似不是216了,不过不要紧,我们调整调整就是了:
|
iPhone |
ipad |
| 竖屏(portrait) |
216 |
264 |
| 横屏(landScape) |
140 |
352 |
我们采取的方法就是在textField(有可能是其他控件)接收到弹出键盘事件时把self.view整体上移216px了(我们就以iPhone竖屏为例了)。
有关View的frame,origin,size之类的知识点不懂的请参看我的另一篇博文: <<有关View的几个基础知识点>>
首先我们要设置textField的代理,我们就设为当前控制器了。
textField,delegate=self;
然后我们在当前控制器实现下面三个委托方法:
[java] view plain copy
print?
-
- (void)textFieldDidBeginEditing:(UITextField *)textField
-
{
-
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
-
{
-
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];
-
[textField resignFirstResponder];
-
}
本文转自 卓行天下 51CTO博客,原文链接:http://blog.51cto.com/9951038/1772565,如需转载请自行联系原作者