Posted By

leftspin on 04/22/12


Tagged

objc animation CALayer


Versions (?)

Example from IVM-Awesomesauce


 / Published in: Objective C
 

URL: https://github.com/leftspin/IVM-Awesomesauce/blob/master/IVMAwesomesauce/RootViewController.m

A snippet of code from IVM-Awesomesauce that shows how to use included classes to perform a custom animation between two UIViewControllers.

  1. - (IBAction)leButtonTapped:(id)sender
  2. {
  3. NextViewController *nvc = [[NextViewController alloc] initWithNibName:@"NextViewController" bundle:nil] ;
  4.  
  5. // This performs a flipboard-like animation
  6. ASAnimatedTransition *animatedTransition = [[ASAnimatedTransition alloc] init] ;
  7. animatedTransition.sourceView = self.view ;
  8. animatedTransition.destinationView = nvc.view ;
  9. animatedTransition.hostView = self.view ;
  10. animatedTransition.initializeAnimationBlock = ^(AnimationView *animationView, CALayer *sourceLayer, CALayer *destinationLayer)
  11. {
  12. CATransform3D transform = CATransform3DIdentity ;
  13. transform.m34 = 1.0 / -200 ;
  14. transform = CATransform3DTranslate(transform, 0, 5, -25) ;
  15. destinationLayer.transform = transform ;
  16. } ;
  17. animatedTransition.performAnimationBlock = ^(AnimationView *animationView, CALayer *sourceLayer, CALayer *destinationLayer)
  18. {
  19. [CATransaction setAnimationDuration:0.6] ;
  20. sourceLayer.position = CGPointMake(sourceLayer.position.x, -sourceLayer.frame.size.height/2.0) ;
  21. destinationLayer.transform = CATransform3DIdentity ;
  22. } ;
  23. animatedTransition.animationFinishedBlock = ^()
  24. {
  25. [self.navigationController pushViewController:nvc animated:NO] ;
  26. } ;
  27. [animatedTransition performTransition] ;
  28. }

Report this snippet  

You need to login to post a comment.