Skip to content

Instantly share code, notes, and snippets.

@tangqiaoboy
Created December 2, 2013 10:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tangqiaoboy/7747522 to your computer and use it in GitHub Desktop.
Save tangqiaoboy/7747522 to your computer and use it in GitHub Desktop.
- (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