iOS 11 - Keyboard Height is returning 0 in keyboard notification iOS 11 - Keyboard Height is returning 0 in keyboard notification ios ios

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


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.


Try this:

Replace UIKeyboardFrameBeginUserInfoKey with UIKeyboardFrameEndUserInfoKey