0

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

4

2 回答 2

1

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

- (void)keyboardWillShow:(NSNotification *)aNotification 
{
    self.frame = CGRectMake(0,-[size of keyboard],self.frame.size.width,self.frame.size.height);
}
于 2012-04-22T11:52:55.303 回答
0

我从这里拿走了

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

希望能帮助你。
很高兴能帮助你。

于 2012-04-22T12:22:21.563 回答