iOS 12 - UIKeyboardFrameEndUserInfoKey inconsistent

When adding and input accessory view from a view controller and then using:

```

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

```

to then trigger

```

- (void)keyboardWillShow:(NSNotification *)notification

{

NSDictionary *keyboardAnimationDetail = [notification userInfo];


UIViewAnimationCurve curve = [keyboardAnimationDetail[UIKeyboardAnimationCurveUserInfoKey] integerValue];

NSTimeInterval duration = [keyboardAnimationDetail[UIKeyboardAnimationDurationUserInfoKey] doubleValue];


CGRect keyboardRect = [keyboardAnimationDetail[UIKeyboardFrameEndUserInfoKey] CGRectValue];

...

}

```


The keyboardRect height is unreliable in iOS 12. It returns height values that _do not_ match the actual height of the keyboard and the values are inconsistent. This was never an issue in the last 4 versions. Please fix.

Replies

Hi! I'm seeing same kind of issue on my side. Did you manage to solve it?

I noticed the same problem of erroneous keyboard info with IOS 11.2, when rotating device ; I filed a bug report end of Feb 18. Marked as Dupe, no news since.


Bug report #38117524

Summary:

- Value for keyboard height returned by

note.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue

is erroneous after turning iPad from Portrait to Landscape

- This is for a numeric keypad on iPad (numbers at top, special characters below, help line at the top).

- This occurs both on device and in Xcode simulator


Steps to Reproduce:

On iPad, select numeric keypad (numbers at top, special characters below, help line at the top), for a textField

In keyboardWillShow, get the keyboard size, and ask for printing it :

    @objc func keyboardWillShow(_ note : Notification) -> Void {
          if let keyboardSize = (note.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
                    print("keyboardSize", keyboardSize)

Start in landscape, click on field to show keyboard, then turn portrait then return landscape, the keyboard staying displayed on screen.


Expected Results:

Height should be 398 when returning to landscape


Actual Results:

Height is 142 after returning to landscape.

keyboardSize (0.0, 768.0, 1024.0, 398.0) // Landscape, seems correct

keyboardSize (0.0, 1024.0, 768.0, 313.0) // Portrait, effectively smaller in height

keyboardSize (0.0, 768.0, 1024.0, 142.0) // Return to landscape: height is now clearly wrong

keyboardSize (0.0, 626.0, 1024.0, 142.0) // Note: keyboardWillShow is called a second time and removes 142.0 from origin.y.


Version/Build:

IOS 11.2.5 (15D100)

Xcode Version 9.2 beta (9C34b)

OSX Version 10.13.3 (17D102)


Configuration:

iMac (Retina 5K, 27 pouces, fin 2015)

iPad : model MGTX2NF/A