【问题标题】:Keypad is hiding UITextField键盘隐藏 UITextField
【发布时间】:2012-04-22 11:47:18
【问题描述】:

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

【问题讨论】:

  • 您可以为您的文本字段提供滚动视图,只要您单击文本字段,键盘就会出现。

标签: iphone ios5 xcode4.2


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

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

    希望能帮助你。
    乐于助人。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-17
      • 2022-01-23
      • 1970-01-01
      • 2020-05-26
      • 1970-01-01
      • 2011-05-03
      • 2014-11-19
      • 1970-01-01
      相关资源
      最近更新 更多