I have a UI that needs some position adjustments when a keyboard is shown.
The following is used to detect when a keyboard is shown:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
Note: I've tried with both UIKeyboardWillShowNotification and UIKeyboardDidShowNotification
- (void)keyboardWillShow:(NSNotification *)n {
if (isKeyboardShowing)
return;
NSDictionary* userInfo = [n userInfo];
// get the size of the keyboard
CGSize keyboardSize = [[userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
// Animate keyboard shift
[self.view layoutIfNeeded];
[UIView animateWithDuration:0.2f animations:^{
// some animation here
} completion:^(BOOL finished) {
if (finished)
isKeyboardShowing = YES;
}];
For custom keyboards the keyboard size returns {320, 0}. As keyboards can have different heights now, I cannot have static values to change the UI when keyboard is presented.
Is this an issue with ios8? and are there any other methods to dynamically get the keyboard height?
Edit: This is the userInfo Dict:
{name = UIKeyboardDidShowNotification; userInfo = {
UIKeyboardAnimationCurveUserInfoKey = 7;
UIKeyboardAnimationDurationUserInfoKey = "0.25";
UIKeyboardBoundsUserInfoKey = "NSRect: {{0, 0}, {320, 0}}";
UIKeyboardCenterBeginUserInfoKey = "NSPoint: {160, 568}";
UIKeyboardCenterEndUserInfoKey = "NSPoint: {160, 568}";
UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 568}, {320, 0}}";
UIKeyboardFrameEndUserInfoKey = "NSRect: {{0, 568}, {320, 0}}";
}}
Thanks in advance.
Use
CGSize keyboardSize = [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
to get the actual size of the keyboard
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