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

时间:2015-04-20 06:32:00

标签: ios keyboard

自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}}"; }

1 个答案:

答案 0 :(得分: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);
}