小键盘隐藏UITextField
答
您需要在调用键盘时向上移动框架。
- (void)keyboardWillShow:(NSNotification *)aNotification
{
self.frame = CGRectMake(0,-[size of keyboard],self.frame.size.width,self.frame.size.height);
}
答
- (void)textFieldDidBeginEditing:(UITextField *)textField {
if (textField == textField1) {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.5];
[UIView setAnimationBeginsFromCurrentState:YES];
textfield1.frame = CGRectMake(textfield1.frame.origin.x, (textfield1.frame.origin.y - 100.0), textfield1.frame.size.width, textfield1.frame.size.height);
[UIView commitAnimations];
} else if (textField == textField2) {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.5];
[UIView setAnimationBeginsFromCurrentState:YES];
textfield2.frame = CGRectMake(textfield2.frame.origin.x, (textfield2.frame.origin.y - 100.0), textfield2.frame.size.width, textfield2.frame.size.height);
[UIView commitAnimations];
}
}
- (void)textFieldDidEndEditing:(UITextField *)textField {
if (textField == textField1) {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.5];
[UIView setAnimationBeginsFromCurrentState:YES];
textfield1.frame = CGRectMake(textfield1.frame.origin.x, (textfield1.frame.origin.y + 100.0), textfield1.frame.size.width, textfield1.frame.size.height);
[UIView commitAnimations];
} else if (textField == textField2) {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.5];
[UIView setAnimationBeginsFromCurrentState:YES];
textfield2.frame = CGRectMake(textfield2.frame.origin.x, (textfield2.frame.origin.y + 100.0), textfield2.frame.size.width, textfield2.frame.size.height);
[UIView commitAnimations];
}
和触摸:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{ [文本字段resignFirstResponder]; }
希望能帮助你。
乐意提供帮助。
你可以有一个滚动视图为你的文本字段,每当你点击文本字段时,键盘将出现。 – rishi 2012-04-22 11:49:07