转载自: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;
}
本文介绍了一种处理iOS设备上UITextField输入框被键盘遮挡的问题的方法,通过调整视图的位置来实现键盘出现和消失时的界面还原。
460

被折叠的 条评论
为什么被折叠?



