Skip to content

Instantly share code, notes, and snippets.

@MyBigFish
Forked from philipmcdermott/KeyboardHandler.m
Created August 18, 2016 09:57
Show Gist options
  • Save MyBigFish/e817e39f4af287444a261b9c2ce0f741 to your computer and use it in GitHub Desktop.
Save MyBigFish/e817e39f4af287444a261b9c2ce0f741 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