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

自iOS8以来,很多thirdPart键盘显示,我想获得显示时的键盘高度

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}}"; } { 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); }