-(void)textFieldDidBeginEditing:(UITextField *)textField
{
CGRect frame = textField.frame;
//在这里我多加了62,(加上了输入中文选择文字的view高度)这个依据自己需求而定
int offset = (frame.origin.y + 20 * widthPropor)- ( self.view.frame.size.height - 216.0);//键盘高度216
//设置动画的名字
[UIView beginAnimations:@"Animation" context:nil];
//设置动画的间隔时间
[UIView setAnimationDuration:0.42];
//使用当前正在运行的状态开始下一段动画
[UIView setAnimationBeginsFromCurrentState: YES];
if (offset>0) {
//将视图的Y坐标向上移动offset个单位,以使下面腾出地方用于软键盘的显示
self.view.frame = CGRectMake(0, -offset, self.view.frame.size.width, self.view.frame.size.height);
}
//设置动画结束
[UIView commitAnimations];
}
-(void)textFieldDidEndEditing:(UITextField *)textField
{
//设置动画的名字
[UIView beginAnimations:@"Animation" context:nil];
//设置动画的间隔时间
[UIView setAnimationDuration:0.42];
//??使用当前正在运行的状态开始下一段动画
[UIView setAnimationBeginsFromCurrentState: YES];
//设置视图移动的位移
self.view.frame = CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height);
//设置动画结束
[UIView commitAnimations];
}