小键盘隐藏UITextField

问题描述:

我有10个UITextField'正在整个屏幕。当我想改变它们时,我在半屏上得到键盘,所以我不能改变'隐藏'字段。 有没有人知道解决方案?小键盘隐藏UITextField

+1

你可以有一个滚动视图为你的文本字段,每当你点击文本字段时,键盘将出现。 – rishi 2012-04-22 11:49:07

您需要在调用键盘时向上移动框架。

- (void)keyboardWillShow:(NSNotification *)aNotification 
{ 
    self.frame = CGRectMake(0,-[size of keyboard],self.frame.size.width,self.frame.size.height); 
} 

i have taken from here

- (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]; }

希望能帮助你。
乐意提供帮助。