2012-06-25 90 views
1

我想向上滾動我的表單讓UITextField下的鍵盤。它適用於英文鍵盤,但是當我更改爲日文鍵盤時,我的表單只能向上滾動一點點。我調試並發現兩種情況下鍵盤的高度是不同的。日本鍵盤的高度

我做如下

- (void)registerForKeyboardNotifications 
{ 
    [[NSNotificationCenter defaultCenter] addObserver:self 
      selector:@selector(keyboardWasShown:) 
      name:UIKeyboardDidShowNotification object:nil]; 

    [[NSNotificationCenter defaultCenter] addObserver:self 
      selector:@selector(keyboardWillBeHidden:) 
      name:UIKeyboardWillHideNotification object:nil]; 
} 

- (void)keyboardWasShown:(NSNotification*)aNotification 
{ 
    NSDictionary* info = [aNotification userInfo]; 

    CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size; 

    NSLog(@"kbSize.height=%0.1f", kbSize.height); 

    UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize.height, 0.0); 
    scrollView.contentInset = contentInsets; 
    scrollView.scrollIndicatorInsets = contentInsets; 
    CGRect aRect = self.view.frame; 
    aRect.size.height -= kbSize.height; 
    if (!CGRectContainsPoint(aRect, activeField.frame.origin)) 
    { 
     CGPoint scrollPoint = CGPointMake(0.0, activeField.frame.origin.y-kbSize.height); 
     [scrollView setContentOffset:scrollPoint animated:YES]; 
    } 
} 

- (void)keyboardWillBeHidden:(NSNotification*)aNotification 
{ 
    UIEdgeInsets contentInsets = UIEdgeInsetsZero; 
    scrollView.contentInset = contentInsets; 
    scrollView.scrollIndicatorInsets = contentInsets; 
} 

- (void)textFieldDidBeginEditing:(UITextField *)textField 
{ 
    activeField = textField; 
} 

- (void)textFieldDidEndEditing:(UITextField *)textField 
{ 
    activeField = nil; 
} 

這裏是信息的結果:

  1. 英文鍵盤:kbSize.height = 216.0

  2. 日語鍵盤:kbSize。 height = 252.0

有沒有人得到這種情況?有人能幫我解決這個問題嗎?

謝謝。

回答

1
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardModeChange:) name:UITextInputCurrentInputModeDidChangeNotification object:nil]; 
+0

您能否爲您的答案提供更多的上下文?這可能有助於解釋你在這裏得到什麼。 –