Friday, 28 September 2012

UIKeyBoard SplitView mode notification in iPAD

NSNotificationCenter is used to find the UIKeyBoard show or hide notification. From iOS5 can get the keyboard change notification (UIKeyboardDidChangeFrameNotification). Normally UIKeyboard have three modes are

  •        Dock
  •        UnDock
  •        Split

 Can find the keyboard show or hide notification by using name UIKeyboardWillHideNotification and UIKeyboardDidShowNotification for DOCK and UNDOCK mode.
In the split view, have to use UIKeyboardDidChangeFrameNotification to find the keyboard showor hide notification.

Register the notification in your  view controller to find keyboard changes in split view mode

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];

NSString *version = [[UIDevice currentDevice] systemVersion]; 
    float version_float = [version floatValue];

        if( version_float > 5.0])  //use notification if system version iOS5 and above
            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShoworHide:) name:UIKeyboardDidChangeFrameNotification object:nil];

        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardDidShowNotification object:nil]; 

In the keyboardWillShoworHide method implementation have to check for the keyboard showing or hiding

BOOL wasKeyboardVisible;
- (void) keyboardWillShoworHide:(NSNotification *)aNotification
    NSDictionary* info = [aNotification userInfo];
    CGRect currentKbRect = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
    CGRect screenRect = [[UIScreen mainScreen] bounds];
    BOOL keyboardVisible = CGRectIntersectsRect(currentKbRect, screenRect);
    if (keyboardVisible && !wasKeyboardVisible) {
     //keyboard visible
    } else if (!keyboardVisible && wasKeyboardVisible) {
    //keyboard hidden
    wasKeyboardVisible = keyboardVisible;

1 comment:

  1. Hi There! Nice blog to read about the iPhone App Development , Iphone apps developers etc. It’s Really Helpful for people who interested in iOS and Android Application Development. Thanks for sharing such useful information with us.