2011-12-16 56 views
0

我正在制作一个简单的iphone应用程序,其中我有一个下面的某些文本字段。 问题是当我通过模拟器中的键盘将数据添加到这些前几个字段中时,键盘也会弹出,而我仍然不使用该键盘进行打字,因为我仍在使用模拟器而不是实际的手机。 现在我无法将数据输入到键盘隐藏的文本字段中。如何摆脱iphone模拟器中的键盘?

很抱歉,如果我的问题是愚蠢的,有可能是的是, 一条捷径,但我新的StackOverflow是我唯一的选择回来时,我无法找到谷歌搜索:)

+0

的可能重复[iPhone - 键盘隐藏文本字段(http://stackoverflow.com/questions/2307200/iphone-keyboard-hides-textfield) – Vladimir 2011-12-16 06:53:43

回答

0

使用你的模拟器的东西用于输入用户输入的键盘和用于向上移动文本字段的写代码,使得键盘不隐藏文本字段。将代表连接到文本字段。

我用这对上下移动:鉴于没有负荷,

{ 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; 
} 

和下面的方法

- (void) keyboardWillShow: (NSNotification*) aNotification 
{  
    int position = 0; 


    if ([txtfld1 isFirstResponder]) 
     position = 120; 
    else if ([txtfld2 isFirstResponder]) position = 120; 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.3]; 
    CGRect rect = [[self view] frame]; 
    rect.origin.y -= position; 
    [[self view] setFrame: rect]; 
    [UIView commitAnimations]; 

} 
- (void) keyboardWillHide: (NSNotification*) aNotification 

{ 
    int position = 0; 


    if ([txtfld1 isFirstResponder]) 
     position = 120; 
    else if ([txtfld2 isFirstResponder]) position = 120; 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.3]; 
    CGRect rect = [[self view] frame]; 
    rect.origin.y += position; 
    [[self view] setFrame: rect]; 
    [UIView commitAnimations]; 
} 
0

只需添加文本框代表..这就是它的委托方法

- (BOOL)textFieldShouldReturn:(UITextField *)textField 
    { 
     ["your Textfiled object Name" resignFirstResponder]; 
    } 

设置您的所有文本文件如上所述。你的键盘将被解雇。我建议让你的文本框在滚动视图中。它可以帮助你

0

你可能正在寻找类似于Android中的“后退按钮”,它在任何情况下都会关闭Android模拟器上的键盘。在iOS模拟器中,您没有可以像那样工作的快捷方式或按钮。您将能够通过返回按钮来关闭键盘,但前提是您已在代码中首先连接了UITextFieldDelegateUse this code使您的返回按钮“工作”。

0

另外,您可以从属性检查器中添加一个RETURN键(DONE,GO ...)。

0

我正在使用以下答案来解决问题。我希望这对你真的很有帮助。 您只需使用此代码在您看来Controller.m或者文件

- (void)textFieldDidBeginEditing:(UITextField *)textField 
{ 
    [self animateTextField:textField up:YES]; 
} 


- (void)textFieldDidEndEditing:(UITextField *)textField 
{ 
    [self animateTextField:textField up:NO]; 
}