本文共 1246 字,大约阅读时间需要 4 分钟。
转载自:http://hi.baidu.com/xuen2460697/item/17e04807bed6f2873d42e265
键盘遮挡无非是要上移view,然后还原.
1 2 3 4 5 6 7 8 9 10 11 12 13 | //键盘出现时,view上移 [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.3]; [UIView setAnimationDelegate:self]; self.view.frame = CGRectMake(0, -130, 320, 460); //130就是上移的距离 [UIView commitAnimations]; //键盘消失后,view还原 [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.3]; [UIView setAnimationDelegate:self]; self.view.frame = CGRectMake(0, 0, 320, 460); //还原 [UIView commitAnimations]; |
//chenyong textfield委托方法,当按下Return时键盘收起
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
[UIView setAnimationDelegate:self];
self.view.frame = CGRectMake(0, 0, 320, 460);//还原
[UIView commitAnimations];
[textField resignFirstResponder];
return YES;
}
//-(BOOL)textFieldShouldEndEditing:(UITextField *)textField
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
[UIView setAnimationDelegate:self];
self.view.frame = CGRectMake(0, -130, 320, 460);//130就是上移的距离
[UIView commitAnimations];
return YES;
}