Last active
August 14, 2017 04:05
-
-
Save philipmcdermott/5183731 to your computer and use it in GitHub Desktop.
Getting the keyboard height on iOS.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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