OK, I know I can read the keyboard size using the notification UIKeyboardWillShowNotification and this
keybSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
but this will just be available when the keyboard shows.
but the problem is this: I have a window that has to adjust itself to a new position when the keyboard is visible and when iPhone rotates. When I rotate the iPhone both delegates method willRotateToInterfaceOrientation and didRotateFromInterfaceOrientation run and handle the rotation. Inside these methods I need to know the current keyboard height, so I can position the view properly. The problem is that the method fired by the UIKeyboardWillShowNotification notification runs after the rotation was handled by the delegate methods.
The order the methods run is:
In other words, the keyboard height is just read at the end, what means both methods 1 and 2 will use the old keyboard height.
My question is: is there a way to read the keyboard height of a visible keyboard directly instead of relying in methods fired by notifications?
thanks
Go to Settings > Accessibility > Keyboards, tap Full Keyboard Access, then turn on Full Keyboard Access.
Tap and hold on the emoji or globe icon on the keyboard. You will see three keyboard icons . Tap the left icon to shrink the keyboard to the left or the right icon to shrink the keyboard to the right. Tap the middle icon to return to the full-sized keyboard.
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.
Go to Settings > General > Keyboard > Keyboards. Tap a language at the top of the screen, then select an alternative layout from the list.
You can use this code snippet to explore the view hierarchy:
- (void)printSubviews:(UIView *)aView {
NSLog(@"%@ - %@", [aView class], NSStringFromCGRect([aView frame]));
for (UIView *view in [aView subviews]) {
[self printSubviews:view];
}
}
- (void)printAllViews {
for (UIWindow *window in [[UIApplication sharedApplication] windows]) {
[self printSubviews:window];
}
}
You'll see that it's pretty easy to figure out the keyboard size from the values you get.
Alternatively, you can import UIKeyboard.h
(you can find it on the internet). It includes a method to get the default keyboard size for various interface orientations. However, that would make use of private APIs, so you might want to be careful with it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With