调用键盘时,输入框被遮掩的处理办法:主要是要响应textFieldDidBeginEditing这个方法,在用户完成输入后,用户屏幕应该复原,
需要响应textFieldDidBeginEditing,感谢
“感恩的心”提供的代码,但是还有点小小的bug,我修改后的代码如下:
BOOL IsMove;
float width;
float height;
////////////////
//打开键盘时调整位置
-(void)textFieldDidBeginEditing:(UITextField *)textField{
if (textField == self.emailTextField) {
NSTimeInterval animationDuration = 0.30f;
[UIView beginAnimations:@"ResizeForKeyBoard" context:nil];
[UIView setAnimationDuration:animationDuration];
width = self.view.frame.size.width;
height = self.view.frame.size.height;
CGRect rect = CGRectMake(0.0f, -35, width, height);
self.view.frame = rect;
[UIView commitAnimations];
IsMove = true;
}
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
//最下边那个文本框的
if (IsMove == true) {
NSTimeInterval animationDuration = 0.30f;
[UIView beginAnimations:@"ResizeForKeyboard" context:nil];
[UIView setAnimationDelay:animationDuration];
self.view.frame = CGRectMake(0, 0, width, height);
[UIView commitAnimations];
IsMove = false;
}
[textField resignFirstResponder];
return YES;
}