Get the height of keyboard doesn't work on IOS 11 beta Get the height of keyboard doesn't work on IOS 11 beta swift swift

Get the height of keyboard doesn't work on IOS 11 beta


Use UIKeyboardFrameEndUserInfoKey instead of UIKeyboardFrameBeginUserInfoKey

So changing your code to the following will fix your issue:

if let userInfo = notification.userInfo {    if let keyboardSize = (userInfo[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue {        print(keyboardSize)    }}


I have the same issue. The answer of Doug Amos is right. I just want to make it clearer. Here is my code:

@objc func keyboardWillShow(notification:NSNotification){        var userInfo = notification.userInfo!        var keyboardFrame:CGRect = (userInfo[UIKeyboardFrameBeginUserInfoKey] as! NSValue).cgRectValue        if keyboardFrame.size.height <= 0 { // to fix bug on iOS 11            keyboardFrame = (userInfo[UIKeyboardFrameEndUserInfoKey] as! NSValue).cgRectValue        }        keyboardFrame = self.view.convert(keyboardFrame, from: nil)    }


I used this code in my app with Swif 3+

    var userInfo = notification.userInfo    if let keyboardFrame = (userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue{        print(keyboardFrame.height)        if keyboardFrame.size.height <= 0 { // To fix bug on iOS 11            if let newKeyboardFrame = (userInfo?[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue{                print(newKeyboardFrame.height)            }        }    }    view.layoutIfNeeded()