iOS 11 - Keyboard Height Is Returning 0 in Keyboard Notification

iOS 11 - Keyboard Height is returning 0 in keyboard notification

Use this:

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

For Swift, you can use:

let keyboardSize = (notification.userInfo![UIKeyboardFrameEndUserInfoKey] as! NSValue).cgRectValue.size

swift iOS11 - identify keyboardSize height doesn't work anymore

Use UIKeyboardFrameEndUserInfoKey instead of UIKeyboardFrameBeginUserInfoKey

Swift keyboard Height return 0

what about to check it with UIKeyboardFrameEndUserInfoKey wouldn't this work?

UIKeyboardEventArgs FrameBegin Height returns 0 after first click

Solution:

Use FrameEnd.Height instead of FrameBegin.Height.

References:

UIKeyboardFrameBeginUserInfoKey

The key for an NSValue object containing a CGRect that identifies the starting frame rectangle of the keyboard in screen coordinates. The frame rectangle reflects the current orientation of the device.

UIKeyboardFrameEndUserInfoKey

The key for an NSValue object containing a CGRect that identifies the ending frame rectangle of the keyboard in screen coordinates. The frame rectangle reflects the current orientation of the device.

Apple's Documentations:
https://developer.apple.com/documentation/uikit/uikeyboardframebeginuserinfokey
https://developer.apple.com/documentation/uikit/uikeyboardframeenduserinfokey

Other related case: iOS 11 - Keyboard Height is returning 0 in keyboard notification

The height on my soft keyboard changes when triggered multiple times

The problem is that you are examining the wrong frame:

UIKeyboardFrameBeginUserInfoKey

When the keyboard is shown, what its frame height is at the beginning of the showing process is of no interest to you. What you want to know is the frame at the end of the showing process:

UIKeyboardFrameEndUserInfoKey

Also, it looks like you are getting notified of the wrong thing. You have not shown what notification you are registered for, but the name of your method, keyboardWasShown, suggests that your are getting notified when the keyboard did show. That's too late; this notification is almost never of any interest. You want to know when the keyboard will show.

can't get correct value of keyboard height in iOS8

Use

NSValue* keyboardFrameBegin = [keyboardInfo valueForKey:UIKeyboardFrameEndUserInfoKey];


Related Topics



Leave a reply



Submit