首先创建一个textFiled 并实现起代理方法
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
//设置动画的名字
[UIView beginAnimations:@"Animation" context:nil];
//设置动画的间隔时间
[UIView setAnimationDuration:0.20];
//??使用当前正在运行的状态开始下一段动画
[UIView setAnimationBeginsFromCurrentState: YES];
//设置视图移动的位移
self.view.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y - , self.view.frame.size.width, self.view.frame.size.height);
//设置动画结束
[UIView commitAnimations];
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
//设置动画的名字
[UIView beginAnimations:@"Animation" context:nil];
//设置动画的间隔时间
[UIView setAnimationDuration:0.20];
//??使用当前正在运行的状态开始下一段动画
[UIView setAnimationBeginsFromCurrentState: YES];
//设置视图移动的位移
self.view.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y +, self.view.frame.size.width, self.view.frame.size.height);
//设置动画结束
[UIView commitAnimations];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[_text resignFirstResponder];
return YES;
}