Created
June 20, 2014 19:00
-
-
Save andkon/7aa32a71af81b57a4fbb to your computer and use it in GitHub Desktop.
Custom dismissal animation
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
@interface RootVC : UIViewController <UIViewControllerTransitioningDelegate> |
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
#import "TwoStepTransition.h" | |
- (id <UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed | |
{ | |
TwoStepTransition *twoStep = [[TwoStepTransition alloc] init]; | |
return twoStep; | |
} |
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
#import <Foundation/Foundation.h> | |
@interface TwoStepTransition : NSObject <UIViewControllerAnimatedTransitioning> | |
@end |
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
@implementation TwoStepTransition | |
// Just like w/ BouncyTransition | |
- (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext | |
{ | |
return 1.0f; | |
} | |
- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext | |
{ | |
// 1. Get the to and from VCs (they're flipped compared to the presentingModal transition) | |
UIViewController *toVC = [transitionContext viewControllerForKey:UIViewControllerTransitionContextToViewControllerKey]; | |
UIViewContorller *fromVC = [transitionContext viewControllerForKey:UIViewControllerTransitionContextFromViewControllerKey]; | |
// they're also both already in the container view, so no need to add 'em | |
// 2. Implement keyframe animations | |
__block CGRect presentedFrame = [transitionContext initialFrameForViewController:fromVC]; | |
[UIView animatedKeyframesWithDuration:1.0f | |
delay:0.0f | |
options:0 | |
animations:^{ | |
[UIView addKeyframeWithRelativeStartTime:0.0 | |
relativeDuration:0.8 | |
animations:^{ | |
fromVC.view.frame = CGRectMake( | |
presentedFrame.origin.x, | |
-20, | |
presentedFrame.size.width, | |
presentedFrame.size.height | |
); | |
}]; | |
[UIView addKeyframeWithRelativeStartTime:0.8 | |
relativeDuration:0.2 | |
animations:^{ | |
presentedFrame.origin.y += CGRectGetHeight(presentedFrame) + 20; | |
fromVC.view.frame = presentedFrame; | |
fromVC.view.transform = CGAffineTransformMakeRotation(0.2); | |
}]; | |
} completed:^(BOOL finished) { | |
[transitionContext completeTransition:YES]; | |
}]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment