Created
June 6, 2013 13:59
-
-
Save darcwader/5721712 to your computer and use it in GitHub Desktop.
Rotation Animation using Core Animation
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
CATransform3D transform = CATransform3DIdentity; | |
transform.m34 = 1.0/700.0; | |
transform = CATransform3DRotate(transform, M_PI, 0, 1, 0); | |
CATransform3D transform2 = CATransform3DRotate(transform, -M_PI/2, 0, 1, 0); | |
CATransform3D transform3 = CATransform3DRotate(transform2, -M_PI/2, 0, 1, 0); | |
CALayer *layer = self.cardView.layer; | |
CABasicAnimation *rotation = [CABasicAnimation animationWithKeyPath:@"transform"]; | |
rotation.fromValue = [NSValue valueWithCATransform3D:transform]; | |
rotation.toValue = [NSValue valueWithCATransform3D:transform2]; | |
rotation.duration = DURATION; | |
CABasicAnimation *rotation2 = [CABasicAnimation animationWithKeyPath:@"transform"]; | |
rotation2.fromValue = [NSValue valueWithCATransform3D:transform2]; | |
rotation2.toValue = [NSValue valueWithCATransform3D:transform3]; | |
rotation2.duration = DURATION/2; | |
rotation2.beginTime = DURATION/2; | |
CABasicAnimation *translation = [CABasicAnimation animationWithKeyPath:@"position"]; | |
translation.fromValue = [NSValue valueWithCGPoint:self.cardView.layer.position]; | |
translation.toValue = [NSValue valueWithCGPoint:CGPointMake(self.cardView.center.x,[[self.cardView superview] center].y-45)]; | |
translation.duration = DURATION; | |
CAAnimationGroup *group = [CAAnimationGroup animation]; | |
group.animations = @[ translation, rotation, rotation2 ]; | |
group.duration = DURATION; | |
group.delegate = self; | |
[layer addAnimation:group forKey:nil]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment