Created
December 12, 2013 16:53
-
-
Save bcapps/7931226 to your computer and use it in GitHub Desktop.
The category we use in Velocity for adjusting a scroll view's insets when the keyboard shows and hides - behavior which used to be automatic in iOS 6 and is now manual in iOS 7. Call this method from observing both `UIKeyboardWillHideNotification` and `UIKeyboardWillShowNotification`.
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
@implementation UIViewController (LCKAdditions) | |
- (void)adjustScrollView:(UIScrollView *)scrollView forKeyboardChangeNotification:(NSNotification *)notification { | |
NSDictionary *keyboardInfo = [notification userInfo]; | |
CGRect keyboardFrame = [[keyboardInfo valueForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue]; | |
CGRect convertedFrame = [scrollView.superview convertRect:keyboardFrame fromView:scrollView.window]; | |
CGFloat keyboardHeight = CGRectGetHeight(convertedFrame); | |
UIEdgeInsets contentInsets = scrollView.contentInset; | |
if ([notification.name isEqualToString:UIKeyboardWillShowNotification]) { | |
contentInsets.bottom = keyboardHeight; | |
} | |
else if ([notification.name isEqualToString:UIKeyboardWillHideNotification]) { | |
contentInsets.bottom = self.bottomLayoutGuide.length; | |
} | |
scrollView.contentInset = contentInsets; | |
scrollView.scrollIndicatorInsets = contentInsets; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment