iOS 11 - Keyboard Height is returning 0 in keyboard notification
Solution 1:
Use this:
CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
For Swift, you can use:
let keyboardSize = (notification.userInfo![UIKeyboardFrameEndUserInfoKey] as! NSValue).cgRectValue.size
Solution 2:
Replace UIKeyboardFrameBeginUserInfoKey
with
UIKeyboardFrameEndUserInfoKey
The below is from Apple Docs.
UIKeyboardFrameBeginUserInfoKey- The key for an NSValue object containing a CGRect that identifies the start frame of the keyboard in screen coordinates.
UIKeyboardFrameEndUserInfoKey - The key for an NSValue object containing a CGRect that identifies the end frame of the keyboard in screen coordinates.
Solution 3:
Try this:
Replace UIKeyboardFrameBeginUserInfoKey
with UIKeyboardFrameEndUserInfoKey
Solution 4:
This issue is happening on iOS 11.
Replace
"UIKeyboardFrameBeginUserInfoKey" with "UIKeyboardFrameEndUserInfoKey"
as shown below would fix the issue
Objective-C Code :
CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
Swift 2.3 :
let keyboardSize = (NfnPsgVar.userInfo![UIKeyboardFrameEndUserInfoKey] as? NSValue)?.CGRectValue().size
Swift 3 :
let keyboardSize = (notification.userInfo![UIKeyboardFrameEndUserInfoKey] as! NSValue).cgRectValue.size