I used :
NotificationCenter.default.addObserver(self, selector:#selector(keyboardWillShow), name: .UIKeyboardWillShow, object: nil)
@objc func keyboardWillShow(notification: NSNotification) {
if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
let keyboardHeight : Int = Int(keyboardSize.height)
print("keyboardHeight",keyboardHeight)
KeyboardHeightVar = keyboardHeight
}
}
to change to get the height of the keyboard, but the height doesn't include the suggestions bar. How do I get the value of the keyboard height plus the suggestions bar height?
First you need to register for notification that triggered when keyboard will be visible.
Get keyboard height in method...
Use
UIKeyboardFrameEndUserInfoKey
instead ofUIKeyboardFrameBeginUserInfoKey
andUIKeyboardDidShow
instead ofUIKeyboardWillShow
.Try using
UIKeyboardDidShow
instead.You'll get the callback in keyboardWasShown method whenever the keyboard is appear on the screen,
Using the
UIKeyboardFrameEndUserInfoKey
instead ofUIKeyboardFrameBeginUserInfoKey
returns the correct keyboard height. For example, if the keyboard without the toolbar, it returns 216.0 height. With the toolbar - 260.0