Created
September 29, 2014 05:27
-
-
Save sdpjswl/a5db9a4682d4689e14ff to your computer and use it in GitHub Desktop.
Adjust ScrollView when keyboard appears
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
// call "registerForKeyboardNotifications" to enable | |
- (void)registerForKeyboardNotifications { | |
[[NSNotificationCenter defaultCenter] addObserver:self | |
selector:@selector(keyboardWasShown:) | |
name:UIKeyboardDidShowNotification object:nil]; | |
[[NSNotificationCenter defaultCenter] addObserver:self | |
selector:@selector(keyboardWillBeHidden:) | |
name:UIKeyboardWillHideNotification object:nil]; | |
} | |
- (void)keyboardWasShown:(NSNotification*)aNotification { | |
NSDictionary* info = [aNotification userInfo]; | |
CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size; | |
UIEdgeInsets contentInsets = UIEdgeInsetsMake(scrollViewObject.contentInset.top, 0.0, kbSize.height, 0.0); | |
scrollViewObject.contentInset = contentInsets; | |
scrollViewObject.scrollIndicatorInsets = contentInsets; | |
} | |
- (void)keyboardWillBeHidden:(NSNotification*)aNotification { | |
UIEdgeInsets contentInsets = UIEdgeInsetsMake(scrollViewObject.contentInset.top, 0.0, 0.0, 0.0); | |
scrollViewObject.contentInset = contentInsets; | |
scrollViewObject.scrollIndicatorInsets = contentInsets; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment