How do you calculate the keyboard height on an iPhone X?

The top of the keyboard needs to be about 2 inches from the bottom of the *device* as it is held.


Prior to the iPhone X, this is easy because all devices used the exact same bezel insets, so it's 216 pts from the bottom of the screen.


How do we calculate this height on an iPhone X? Safe area insets alone not sufficient for calculating 2 inches from the bottom of the device.


Here's how I'm doing it now:


@implementation UIScreen(MyExtensions)
- (UIEdgeInsets)standardBezelInsets {
    CGSize iPhoneXSize = CGSizeMake(375, 812);
    if (CGSizeEqualToSize(self.bounds.size, iPhoneXSize)) {
        return (UIEdgeInsets) { .top = 43, .bottom = 74 }; // 290 - 216
    }
    return UIEdgeInsetsZero;
}
@end

@implementation MyKeyboardView
- (CGFloat)preferredHeight {
    return [[UIScreen mainScreen] standardBezelInsets].bottom + 216;
}
...
@end


There are a few problems with that.


Is there a better way?

This question is about the size and layout of a custom keyboard view. It is not a question about reading the size of an existing keyboard.

Did you ever figure this out?

How do you calculate the keyboard height on an iPhone X?
 
 
Q