Skip to content

Instantly share code, notes, and snippets.

@Ithoughts
Forked from philipmcdermott/KeyboardHandler.m
Created October 15, 2015 05:52
Show Gist options
  • Save Ithoughts/f1a5230375636146a84b to your computer and use it in GitHub Desktop.
Save Ithoughts/f1a5230375636146a84b to your computer and use it in GitHub Desktop.
Getting the keyboard height on iOS.
- (void)viewDidAppear:(BOOL) animated {
[super viewDidAppear:animated];
// Register notification when the keyboard will be show
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
// Register notification when the keyboard will be hide
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];
}
- (void)keyboardWillShow:(NSNotification *)notification {
CGRect keyboardBounds;
[[notification.userInfo valueForKey:UIKeyboardFrameBeginUserInfoKey] getValue:&keyboardBounds];
// Do something with keyboard height
}
- (void)keyboardWillHide:(NSNotification *)notification {
CGRect keyboardBounds;
[[notification.userInfo valueForKey:UIKeyboardFrameBeginUserInfoKey] getValue:&keyboardBounds];
// Do something with keyboard height
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment