Skip to content

Instantly share code, notes, and snippets.

@evadne
Created December 10, 2010 10:08
Show Gist options
  • Save evadne/736046 to your computer and use it in GitHub Desktop.
Save evadne/736046 to your computer and use it in GitHub Desktop.
- (void) handleKeyboardNotification:(NSNotification *)inNotification {
if (!self.contentView)
return;
CGRect (^rectFromScreenRect) (CGRect inRect) = ^ (CGRect inRect) { return [self.view convertRect:[self.view.window convertRect:inRect fromWindow:nil] fromView:nil]; };
id (^notificationObject) (id inKey) = ^ (id inKey) { return [inNotification.userInfo objectForKey:inKey]; };
CGRect (^rectFromValue) (id inValueObject) = ^ (id inValueObject) { return [((NSValue *)inValueObject) CGRectValue]; };
CGFloat keyboardMinYFrom = rectFromScreenRect(rectFromValue(notificationObject(UIKeyboardFrameBeginUserInfoKey))).origin.y,
keyboardMinYTo = rectFromScreenRect(rectFromValue(notificationObject(UIKeyboardFrameEndUserInfoKey))).origin.y;
UIViewAnimationCurve animationCurve = [(NSNumber *)notificationObject(UIKeyboardAnimationCurveUserInfoKey) intValue];
NSTimeInterval animationDuration = [(NSNumber *)notificationObject(UIKeyboardAnimationDurationUserInfoKey) doubleValue];
if (keyboardMinYFrom == keyboardMinYTo)
return;
CGFloat viewMaxY = self.view.bounds.size.height,
contentViewMaxYFrom = self.contentView.frame.origin.y + self.contentView.frame.size.height,
contentViewMaxYTo = (keyboardMinYTo > viewMaxY) ? viewMaxY : keyboardMinYTo;
[UIView beginAnimations:@"MLAutoresizingModalFormSheetViewControllerContentViewResizingAnimation" context:nil];
[UIView setAnimationCurve:animationCurve];
[UIView setAnimationDuration:animationDuration];
CGRect contentViewFrameEnd = contentView.frame;
contentViewFrameEnd.size.height += (contentViewMaxYTo - contentViewMaxYFrom);
contentView.frame = contentViewFrameEnd;
[UIView commitAnimations];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment