As many of you know iOS 5 introduced a slick split keyboard for thumb-typing. Unfortunately, I have some UI that is dependent on the normal full-screen keyboard layout. One of my view controllers presents the user with a text entry sheet, and if they click into a textField that would be covered by the keyboard, it slides up along with the keyboard. This action is unnecessary with the split keyboard.
Is there a way to check which keyboard layout is in use before it pops up?
Thanks!
When the keyboard is docked, UIKeyboardWillShowNotification
will be raised. If the keyboard is split or undocked, no keyboard notifications are raised.
If a keyboard is docked, UIKeyboardWillShowNotification
will be raised, and the following will be true:
[[[notification userInfo] valueForKey:@"UIKeyboardFrameChangedByUserInteraction"] intValue] == 1
If a keyboard is undocked, UIKeyboardWillHideNotification
will be raised, and the above statement will also be true.
Using this information has been adequate for me to code my user interface.
Note: this might be a violation of Apple's guidelines, I'm not sure.
This is the solution which works with iPad split keyboards (originally from the blog linked in Zeeshan's comment)
[[NSNotificationCenter defaultCenter]
addObserverForName:UIKeyboardDidChangeFrameNotification
object:nil
queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification * notification)
{
CGRect keyboardEndFrame =
[[notification.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
CGRect screenRect = [[UIScreen mainScreen] bounds];
if (CGRectIntersectsRect(keyboardEndFrame, screenRect))
{
// Keyboard is visible
}
else
{
// Keyboard is hidden
}
}];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With