2013-05-10 70 views
1

我有我的UI幾個uitextfields其中鍵盤會重疊很少,它們在我的屏幕底部的uitextfields的,來處理這個我已經實現像如何手動發送UIKeyboard通知

- (void)keyboardWasShown:(NSNotification*)aNotification 
- (void)keyboardWillBeHidden:(NSNotification*)aNotification 

和UIKeyboard通知我uitextfields keyboard returnKeyType is UIReturnKeyNext因此,當用戶點擊下一個按鈕時,我正在將我的下一個文本框設爲becomeFirstResponder但是,當鍵盤隱藏的文本字段成爲第一響應者時,其框架不會更改並更新到可見區域邊界因爲通知只觸發fo,所以在uikeyboard之外當我點擊一個文本框時,第一次。 我需要在每個becomeFirstResponder事件中觸發此keyboardWasShown方法。 提前感謝任何幫助。

回答

0

我建議使用一個嵌入式替換庫TPKeyboardAvoiding,它將處理視圖的所有移動。如果,由於屏幕鍵盤,文本字段將被隱藏。它非常易於使用,而且運作良好。

1

首先確保你在這兩種方法中的代碼是正確的,並考慮到當你將第一響應者從UITextField更改爲另一個時,會有兩個通知sendet,一個用於鍵盤隱藏,另一個用於顯示鍵盤。

我不知道你是怎麼處理這個通知,如果你有機會到文本字段,但我成功地實現了只用的UITextFields

-(BOOL)textFieldShouldReturn:(UITextField *)textField委託方法的一些文本的Fileds的scrolling行爲(移動內容了,因爲鍵盤是隱藏的)

-(void)textFieldDidBeginEditing:(UITextField *)textField(移動內容,因爲鍵盤會出現)

使用這種方法,你可以處理內容的運動,即使你的文本字段已設置爲inputView其他視圖像UIPickerView。

+0

更改視圖的框架與鍵盤的框架 – 2013-05-10 12:17:15

0

這是我如何實現我的代碼:

1)我的看法是一個UIScrollView。

2)我在我的視圖中有多個UITextField,並使用標籤ID來區分它們。當用戶點擊一個的UITextField,該委託被稱爲移動的UIScrollView:

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField { 

switch (textField.tag) 
{ 
    case 0: 
     [myScrollView setContentOffset:CGPointMake(0, 18) animated:YES]; 
     break; 
    case 1: 
     [myScrollView setContentOffset:CGPointMake(0, 56) animated:YES]; 
     break; 
    case 2: 
     [myScrollView setContentOffset:CGPointMake(0, 94) animated:YES]; 
     break; 
    case 3: 
     [myScrollView setContentOffset:CGPointMake(0, 132) animated:YES]; 
     break; 
    case 4: 
     [myScrollView setContentOffset:CGPointMake(0, 170) animated:YES]; 
     break; 
    case 5: 
     [myScrollView setContentOffset:CGPointMake(0, 208) animated:YES]; 
     break; 
    case 6: 
     [myScrollView setContentOffset:CGPointMake(0, 246) animated:YES]; 
     break; 
    case 7: 
     [myScrollView setContentOffset:CGPointMake(0, 284) animated:YES]; 
     break; 
    case 8: 
     [myScrollView setContentOffset:CGPointMake(0, 322) animated:YES]; 
     break; 
    default: 
     break; 
} 
return YES; 
} 

3)我也有UITextView的,並使用該委託來達到同樣的效果:

- (BOOL)textViewShouldBeginEditing:(UITextView *)textView { 

if(textView.tag == 0) 
{ 
    [myScrollView setContentOffset:CGPointMake(0, 360) animated:YES]; 
    // do some stuff... 
} 
if(textView.tag == 1) 
{ 
    [myScrollView setContentOffset:CGPointMake(0, 504) animated:YES]; 
    // do some stuff... 
} 
return YES; 
} 

注意: CGPointMake(0, 123)值取決於您自己的文本字段座標。