ios UIView下面有UITextField,键盘弹出影响输入TextField的内容,解决办法
在viewdidload的时候,把每个TextField设好tag。之后就可以根据最下面的UITextField的内容来判断键盘的弹出和关闭了
有的TextField* name
name.tag = 2;
下面就是当tag==2的情况下,才能够把界面谈到上面去。
- (void)textFieldDidBeginEditing:(UITextField *)textField
{ //当点触textField内部,开始编辑都会调用这个方法。textField将成为first responder
if (textField.tag == 2) {
NSTimeInterval animationDuration = 0.30f;
CGRect frame = self.view.frame;
frame.origin.y -=216;
frame.size.height +=216;
self.view.frame = frame;
[UIViewbeginAnimations:@"ResizeView"context:nil];
[UIView setAnimationDuration:animationDuration];
self.view.frame = frame;
[UIViewcommitAnimations];
}
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{//当用户按下ruturn,把焦点从textField移开那么键盘就会消失了
// textField
if (textField.tag == 2) {
NSTimeInterval animationDuration = 0.30f;
CGRect frame = self.view.frame;
frame.origin.y +=216;
frame.size. height -=216;
self.view.frame = frame;
//self.view移回原位置
[UIViewbeginAnimations:@"ResizeView"context:nil];
[UIView setAnimationDuration:animationDuration];
self.view.frame = frame; www.zzzyk.com
[UIViewcommitAnimations];
}
[textField resignFirstResponder];
returnYES;
}
补充:移动开发 , IOS ,