How to get iOS keyboard height programmatically
July 19, 2015
There is a quite simple way to get iOS keyboard height programmatically. All you need to do is register for the notification
- (void)viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillChangeFrameNotification object:nil];
}
- (void)keyboardWillShow:(NSNotification *)notification {
NSLog(@"%f", [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue].size.height);
}
Don't forget that since iOS8 you have autosuggestions on top of your keyboard that you can hide or show. This section is part of the keyboard and extends it's height accordingly. Make sure to remember this thing when modeling your view with autolayout!
I really advise to log the whole