Created
September 21, 2012 00:17
-
-
Save tewha/3759073 to your computer and use it in GitHub Desktop.
keyboardWillShowNotification
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
- (void)keyboardWillShowNotification:(NSNotification *)notification { | |
dispatch_async(dispatch_get_main_queue(), ^{ | |
UIView *workingView = self.view; | |
CGRect keyboardScreenRect = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue]; | |
CGRect keyboardRect = [workingView convertRect:keyboardScreenRect fromView:nil]; | |
CGRect resizeRect = [workingView convertRect:_resizingView.superview.bounds fromView:_resizingView.superview]; | |
CGRect unionRect = CGRectIntersection(keyboardRect, resizeRect); | |
CGFloat bottom = resizeRect.origin.y + resizeRect.size.height; | |
if (!isinf(unionRect.origin.y)) { | |
bottom = unionRect.origin.y; | |
} | |
CGRect newFrame = _resizingView.frame; | |
newFrame.size.height = [_resizingView.superview convertPoint:(CGPoint){.x=0.0f, .y=bottom} fromView:workingView].y - newFrame.origin.y - 5.0f; | |
_resizingView.frame = newFrame; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment