Last active
December 19, 2015 01:08
-
-
Save ahmattox/5873156 to your computer and use it in GitHub Desktop.
Resize a UIScrollview when the keyboard is shown based on the overlap between the scroll view and keyboard frame
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
- (void) keyboardWillChangeFrame:(NSNotification *)notification { | |
CGRect originalKeyboardFrame = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue]; | |
CGRect keyboardFrame = [[[UIApplication sharedApplication] keyWindow] convertRect:originalKeyboardFrame toView:self]; | |
CGFloat keyboardHeight = CGRectIntersection(keyboardFrame, self.contentScrollView.frame).size.height; | |
[UIView animateWithDuration:[notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue] delay:0 options:[notification.userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue] animations:^{ | |
self.contentScrollView.scrollIndicatorInsets = UIEdgeInsetsMake(0, 0, keyboardHeight, 0); | |
self.contentScrollView.contentInset = UIEdgeInsetsMake(0, 0, keyboardHeight, 0); | |
} completion:nil]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment