Last active
August 29, 2015 14:10
-
-
Save benjaminsnorris/a9e3000dc2493a383548 to your computer and use it in GitHub Desktop.
Responding to keyboard
This file contains hidden or 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
#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