Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

lamfan

macrumors newbie
Original poster
Aug 4, 2008
6
0
[CABasicAnimation animationWithKeyPath:mad:""];

I can't find out how to add the rotation by Core Animation.

Anyone know how to do it?
 
This is a simple sample code for you to reference...

Code:
CAKeyframeAnimation *rotation = [CAKeyframeAnimation animation];
	if (direction == ROTATE_FROM_LEFT) {
		rotation.values = [NSArray arrayWithObjects:
						   [NSValue valueWithCATransform3D:CATransform3DMakeRotation(0.0f, 0.0f, 1.0f, 0.0f)],
						   [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI, 0.0f, 1.0f, 0.0f)],nil];
	} else if (direction == ROTATE_FROM_RIGHT) {
		rotation.values = [NSArray arrayWithObjects:
						   [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI, 0.0f, 1.0f, 0.0f)],
						   [NSValue valueWithCATransform3D:CATransform3DMakeRotation(0.0f, 0.0f, 1.0f, 0.0f)],nil];
	} else {
		rotation.values = [NSArray arrayWithObjects:
						   [NSValue valueWithCATransform3D:CATransform3DMakeRotation(0.0f, 0.0f, 1.0f, 0.0f)],
						   [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI, 0.0f, 1.0f, 0.0f)],
						   [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI * 2, 0.0f, 1.0f, 0.0f)],nil];
		duration *= 2;
	}
	
	rotation.duration = duration;
	rotation.delegate = self;
	
	[[self layer] addAnimation:rotation forKey:@"transform"];

Hope this can help.
:apple:
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.