Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

keyboard size returning wrong values?

On iPad, after subscribing to UIKeyboardDidShowNotification

NSDictionary* info = [aNotification userInfo];
CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
NSLog(@"%@", NSStringFromCGSize(kbSize));

prints {352, 1024}

Isn't this wrong? Not only is height of keyboard so large, how can height be larger than width? Or am i missing something?

like image 864
0xSina Avatar asked Jul 15 '12 19:07

0xSina


1 Answers

I bet the dimensions are reported in a static orientation (the 'window' orientation never actually changes), so I suggest translating that to your view of interest. My normal trick is to convert it to the coordinate space of the window's rootViewController's view:

CGRect rawKeyboardRect = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue];
CGRect properlyRotatedCoords = [self.view.window convertRect:rawKeyboardRect toView:self.view.window.rootViewController.view];

Or a more appropriate view if you have one available. The key is that any coordinates reported in the window's coordinate space are not rotated, even if the window's rootVC's view is.

like image 85
Chris Trahey Avatar answered Sep 24 '22 00:09

Chris Trahey