Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check for split keyboard

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!

like image 644
Evan Davis Avatar asked Oct 20 '11 21:10

Evan Davis


2 Answers

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.

like image 70
David Lawson Avatar answered Sep 30 '22 18:09

David Lawson


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
     }
}];
like image 45
Robert Avatar answered Sep 30 '22 19:09

Robert