2011-12-16 21 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]; 
}