I have created a chat UI in which I have added a constraint
for the tableView
to the bottom of the screen. I am changing the constraint value by ad
The keyboard value reported by UIKeyboardFrameBeginUserInfoKey is different in these two cases in iPhone X:
To get the final height of the keyboard of the keyboard (including the safe area insets) use UIKeyboardFrameEndUserInfoKey.
In iOS 11 (iPhone X particularly), you may consider subtracting the safe area bottom insets.
NSValue *keyboardEndFrameValue = notification.userInfo[UIKeyboardFrameEndUserInfoKey];
if (keyboardEndFrameValue != nil) {
CGRect keyboardSize = [keyboardEndFrameValue CGRectValue];
_keyboardHeight = keyboardSize.size.height;
if (@available(iOS 11.0, *)) {
CGFloat bottomSafeAreaInset = self.view.safeAreaInsets.bottom;
_keyboardHeight -= bottomSafeAreaInset;
} else {
// Fallback on earlier versions
}
}