Created
December 2, 2013 10:15
-
-
Save tangqiaoboy/7747522 to your computer and use it in GitHub Desktop.
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)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext | |
{ | |
UIView *container = transitionContext.containerView; | |
UIViewController *fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; | |
UIViewController *toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; | |
UIView *fromView = fromVC.view; | |
UIView *toView = toVC.view; | |
CGRect beginFrame = CGRectMake(UI_SCREEN_WIDTH, 0, UI_SCREEN_WIDTH, UI_SCREEN_HEIGHT); | |
CGRect endFrame = CGRectMake(0, 0, UI_SCREEN_WIDTH, UI_SCREEN_HEIGHT); | |
UIView *move = nil; | |
if (toVC.isBeingPresented) { | |
toView.frame = endFrame; | |
move = [toView snapshotViewAfterScreenUpdates:YES]; | |
move.frame = beginFrame; | |
} else { | |
move = [fromView snapshotViewAfterScreenUpdates:YES]; | |
move.frame = fromView.frame; | |
[fromView removeFromSuperview]; | |
} | |
[container addSubview:move]; | |
[UIView animateWithDuration:TRANSITION_DURATION delay:0 | |
usingSpringWithDamping:100 initialSpringVelocity:1 | |
options:0 animations:^{ | |
move.frame = toVC.isBeingPresented ? endFrame : beginFrame; | |
} | |
completion:^(BOOL finished) { | |
if (toVC.isBeingPresented) { | |
[move removeFromSuperview]; | |
toView.frame = endFrame; | |
[container addSubview:toView]; | |
} | |
[transitionContext completeTransition: YES]; | |
}]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment