Skip to content

Instantly share code, notes, and snippets.

@bcapps
Created December 12, 2013 16:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bcapps/7931226 to your computer and use it in GitHub Desktop.
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`.
@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