键盘隐藏了UITextField

时间:2012-04-22 11:47:19

标签: iphone ios5 xcode4.2

我有10个UITextField'占据整个屏幕。当我想要更改它们时,我会在半个屏幕上显示键盘,因此,我无法更改“隐藏”字段。 有人知道解决方案吗?

2 个答案:

答案 0 :(得分:1)

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

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

答案 1 :(得分:0)

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

{     [textfield resignFirstResponder]; }

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