2009-08-25 80 views
1

有沒有辦法讓鍵盤消失沒有resignFirstResponder?我有一個UITextField,我希望它能夠接受新的文本,並且仍然可以看到插入點(閃爍的光標),而不會在屏幕上顯示鍵盤。如何讓鍵盤消失?

當我執行[textField resignFirstResponder]時,我仍然可以通過追加textField.text來插入文本,但我看不到插入點了。

有沒有一種標準的方法來使鍵盤動畫化,同時讓我的textField保持第一響應者?

謝謝。

回答

4

找到了這個問題的答案。儘管這並不標準,並且像戴夫說的那樣,可能會成爲應用評論者的禁忌。使用此頁面的代碼爲出發點:

http://unsolicitedfeedback.com/2009/02/06/how-to-customize-uikeyboard-by-adding-subviews/

我在一個動畫塊添加。你可以用一個標準的動畫來消除鍵盤視圖,但是第一響應者會保持這種狀態。真的,鍵盤只是隱藏在屏幕之外。

- (void)hideKeyboard 
{ 
    for (UIWindow *keyboardWindow in [[UIApplication sharedApplication] windows]) { 

    // Now iterating over each subview of the available windows 
    for (UIView *keyboard in [keyboardWindow subviews]) { 

     // Check to see if the view we have referenced is UIKeyboard. 
     // If so then we found the keyboard view that we were looking for. 
     if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES) { 

     // animate the keyboard moving 
     CGContextRef context = UIGraphicsGetCurrentContext(); 
     [UIView beginAnimations:nil context:context]; 
     [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 
     [UIView setAnimationDuration:0.4]; 

     // remove the keyboard 
     CGRect frame = keyboard.frame; 
     // if (keyboard.frame.origin.x >= 0) { 
     if (keyboard.frame.origin.y < 480) { 
      // slide the keyboard onscreen 
      //frame.origin.x = (keyboard.frame.origin.x - 320); 

      // slide the keyboard onscreen 
      frame.origin.y = (keyboard.frame.origin.y + 264); 
      keyboard.frame = frame; 
     } 
     else { 
      // slide the keyboard off to the side 
      //frame.origin.x = (keyboard.frame.origin.x + 320); 

      // slide the keyboard off 
      frame.origin.y = (keyboard.frame.origin.y - 264); 
      keyboard.frame = frame; 
     } 

     [UIView commitAnimations]; 
     } 
    } 
    } 
} 

我在代碼中寫道,將鍵盤排除在屏幕的左側和底部。我不知道當你最終resignFirstResponder會發生什麼事情,但當你這樣做時重置鍵盤框架可能是一個想法。

2

如果存在,那麼它不在iPhone API中記錄。另外,你要求的是沒有意義的。你想要在UITextField中有插入點。太好了。但你還想讓鍵盤消失?那麼,關注焦點的文本字段有什麼意義?你打算如何將數據輸入到文本框?如果你想擁有一個自定義的鍵盤,那麼只需將它顯示在鍵盤上即可。我想不出爲什麼你想讓光標可見,但是而不是有某種數據錄入機制。這會破壞用戶界面慣例,甚至可能會拒絕你的應用程序。

+0

我從來沒有說過我不想要數據輸入系統,只是想讓鍵盤消失。我想創建一個與平常不同的位置的自定義鍵盤。這是您正在考慮的數據輸入系統。 – 2009-08-28 05:49:12