I've added a willShow and willHide observer for the keyboard and am trying to push up the bottom UITextView up to adjust to the UIKeyboard showing. However, my keyboard is getting pushed farther up than just the keyboard frame height. How do I constrain the UITextView bottom anchor to the top of the keyboard?
// Observer method
@objc func handleKeyboardNotification(_ notification: NSNotification) {
if let userInfo = notification.userInfo {
let keyboardFrame = (userInfo[UIResponder.keyboardFrameEndUserInfoKey] as AnyObject).cgRectValue
let isKeyboardShowing = (notification.name == UIResponder.keyboardWillShowNotification)
// Push views up if keyboard is showing, otherwise set constant back to 0
messageInputBottomAnchor?.constant = isKeyboardShowing ? -(keyboardFrame?.height)! : 0
UIView.animate(withDuration: 0.5) {
self.view.layoutIfNeeded()
}
}
}