Created
December 10, 2010 10:08
-
-
Save evadne/736046 to your computer and use it in GitHub Desktop.
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) 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