Skip to content

Instantly share code, notes, and snippets.

@valexa
Last active December 11, 2015 18:49
Show Gist options
  • Save valexa/4644510 to your computer and use it in GitHub Desktop.
Save valexa/4644510 to your computer and use it in GitHub Desktop.
[image setWantsLayer:YES];
CALayer *flayer = [image layer];
[flayer removeAllAnimations];
[backImage setWantsLayer:YES];
CALayer *blayer = [backImage layer];
[blayer removeAllAnimations];
NSView *superView = [image superview];
[superView setWantsLayer:YES];
CATransformLayer *transformLayer = [CATransformLayer layer];
transformLayer.frame = image.bounds;
transformLayer.anchorPointZ = image.bounds.size.height;
transformLayer.anchorPoint = CGPointMake(0.5, 0.0);
[transformLayer addSublayer:flayer];
[transformLayer addSublayer:blayer];
[superView.layer addSublayer:transformLayer];
//rotate the layer to transition to
CATransform3D transform = CATransform3DIdentity;
transform = CATransform3DRotate(transform, DEGREES_TO_RADIANS(90) , 1, 0, 0);
transform = CATransform3DTranslate(transform, 0, -image.bounds.size.height,0);
blayer.transform = transform;
//animate transition to the rotated layer
CABasicAnimation *transformAnimation = [CABasicAnimation animation];
transform = CATransform3DIdentity;
transformAnimation.fromValue = [NSValue valueWithCATransform3D:transform];
transform = CATransform3DIdentity;
transform = CATransform3DRotate(transform, DEGREES_TO_RADIANS(-90) , 1, 0, 0);
transformAnimation.toValue = [NSValue valueWithCATransform3D:transform];
transformAnimation.duration = 9.7;
[transformLayer addAnimation:transformAnimation forKey:@"transform"];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment