Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS8 UIKeyboardWillShowNotification Third party keyboard height [duplicate]

I have a UI that needs some position adjustments when a keyboard is shown.

The following is used to detect when a keyboard is shown:

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

Note: I've tried with both UIKeyboardWillShowNotification and UIKeyboardDidShowNotification

- (void)keyboardWillShow:(NSNotification *)n {
    if (isKeyboardShowing)
    return;

NSDictionary* userInfo = [n userInfo];

// get the size of the keyboard
CGSize keyboardSize = [[userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;


// Animate keyboard shift
[self.view layoutIfNeeded];

[UIView animateWithDuration:0.2f animations:^{
    // some animation here
} completion:^(BOOL finished) {
    if (finished)
        isKeyboardShowing = YES;
}];

For custom keyboards the keyboard size returns {320, 0}. As keyboards can have different heights now, I cannot have static values to change the UI when keyboard is presented.

Is this an issue with ios8? and are there any other methods to dynamically get the keyboard height?

Edit: This is the userInfo Dict:

{name = UIKeyboardDidShowNotification; userInfo = {
    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}}";
}}

Thanks in advance.

like image 815
TreeTree Avatar asked Sep 23 '14 05:09

TreeTree


1 Answers

Use

CGSize keyboardSize = [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;

to get the actual size of the keyboard

like image 86
souvickcse Avatar answered Sep 20 '22 23:09

souvickcse