Today I did a little talk at Cocoaheads Brisbane, Australia. It was on Core Animation and I made a very very very very very simple application which would rotate a single image using CATransform3DIdentity
to give it a nice perspective 3D rotation look.
Here’s the full Xcode 3.1 project: Download.
If you’re interested solely in the transformation here’s the code:
float zDistance = 850; CATransform3D sublayerTransform = CATransform3DIdentity; sublayerTransform.m34 = 1.0 / -zDistance; subLayer.transform = sublayerTransform; CABasicAnimation *flipAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.y"]; flipAnimation.toValue = [NSNumber numberWithDouble:1.0f * M_PI]; flipAnimation.autoreverses = YES; flipAnimation.duration = 2.0f; flipAnimation.repeatCount = 1e100f; flipAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; [subLayer addAnimation:flipAnimation forKey:@"flip"]; |
Where subLayer == your Core Animation layer you want to rotate.
Reference: Core Animation for Mac OS X and the iPhone and Mike Lee.