Skip to content

Instantly share code, notes, and snippets.

@tewha
Created September 21, 2012 00:17
Show Gist options
  • Save tewha/3759073 to your computer and use it in GitHub Desktop.
Save tewha/3759073 to your computer and use it in GitHub Desktop.
keyboardWillShowNotification
- (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