Skip to content

Instantly share code, notes, and snippets.

@benjaminsnorris
Last active August 29, 2015 14:10
Show Gist options
  • Save benjaminsnorris/a9e3000dc2493a383548 to your computer and use it in GitHub Desktop.
Save benjaminsnorris/a9e3000dc2493a383548 to your computer and use it in GitHub Desktop.
Responding to keyboard
#pragma mark - Keyboard Management
- (void)registerForKeyboardNotifications {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}
- (void)keyboardWillShow: (NSNotification*) aNotification {
NSDictionary* info = [aNotification userInfo];
CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize.height, 0.0);
scrollView.contentInset = contentInsets;
scrollView.scrollIndicatorInsets = contentInsets;
}
- (void)keyboardWillHide: (NSNotification*) aNotification {
UIEdgeInsets contentInsets = UIEdgeInsetsZero;
scrollView.contentInset = contentInsets;
scrollView.scrollIndicatorInsets = contentInsets;
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment