//编辑文本框时,键盘出现,然后执行下面代码
{
int offset = frame.origin.y + 32 - (self.view.frame.size.height - 216.0);
//iPhone键盘高度216 iPad 键盘高度352
[UIView setAnimationDuration:0.3f];
//将视图y坐标向上移动offset个单位,以使下面有地方显示键盘
if(offset > 0)self.view.frame = CGRectMake(0.0f, -offset, self.view.frame.size.width,
self.view.frame.size.height);
[UIView commitAnimations];
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
//编辑完成,视图恢复原状
-(void)textFieldDidEndEditing:(UITextField *)textField{
self.view.frame =CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
}