iOS:获取第三方键盘的正确高度



由于iOS8,许多第三方键盘显示,我想在显示时获得键盘高度

NSDictionary* info = [aNotification userInfo]; CGSize kbSize = 
[[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;

但是我可以得到系统键盘的高度,但不能得到第三部分键盘(如SouGouKeyboard),它返回0而不是如何获得正确的高度?

它返回: { UIKeyboardAnimationCurveUserInfoKey = 7; UIKeyboardAnimationDurationUserInfoKey = "0.25"; UIKeyboardBoundsUserInfoKey = "NSRect: {{0, 0}, {320, 0}}"; UIKeyboardCenterBeginUserInfoKey = "NSPoint: {160, 568}"; UIKeyboardCenterEndUserInfoKey = "NSPoint: {160, 568}"; UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 568}, {320, 0}}"; UIKeyboardFrameEndUserInfoKey = "NSRect: {{0, 568}, {320, 0}}"; }

你可以试试这个方法

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:)name:UIKeyboardDidShowNotification    
    object:nil];
 - (void)keyboardWasShown:(NSNotification *)notification
{
  CGSize keyboardSize = [[[notification userInfo]objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
  int height = MIN(keyboardSize.height,keyboardSize.width);
  int width = MAX(keyboardSize.height,keyboardSize.width);
}

最新更新