Skip to content

Instantly share code, notes, and snippets.

@tLewisII
Created October 5, 2013 03:56
Show Gist options
  • Save tLewisII/6836522 to your computer and use it in GitHub Desktop.
Save tLewisII/6836522 to your computer and use it in GitHub Desktop.
Grid ViewController Transitions
-(NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext {
return .7;
}
-(void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext {
UIViewController *toController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
UIViewController *fromController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
CGRect finalFrame = [transitionContext finalFrameForViewController:toController];
UIView *containerView = [transitionContext containerView];
toController.view.frame = finalFrame;
[containerView addSubview:toController.view];
for(NSInteger i = 0; i < 9; i++) {
for(NSInteger j = 0; j < 5; j++) {
UIView *square = [fromController.view resizableSnapshotViewFromRect:CGRectMake(j * 64, i * 64, 64, 64) afterScreenUpdates:NO withCapInsets:UIEdgeInsetsZero];
square.frame = CGRectMake(j * 64, i * 64, 64, 64);
[containerView addSubview:square];
[UIView animateWithDuration:[self transitionDuration:transitionContext] delay:(j + i) * .1 usingSpringWithDamping:.6 initialSpringVelocity:0 options:UIViewAnimationOptionCurveLinear animations:^{
square.center = containerView.center;
square.layer.transform = CATransform3DMakeScale(.1, .1, 1.0);
} completion:^(BOOL finished) {
[square removeFromSuperview];
if(i == 8 && j == 4)
[transitionContext completeTransition:YES];
}];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment