Reputation: 111
I am trying to animate my image by having it rotate clockwise, and shrink down. So far, it is only going counter-clockwise. I have tried both positive and negative values for the value/Key path of rotating along Z, but it changed nothing.
[window addSubview:splashView];
[window bringSubviewToFront:splashView];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2.0];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(startupAnimationDone:finished:context:)];
splashView.frame = CGRectMake(160, 284, 0, 0);
[splashView.layer setValue:[NSNumber numberWithInt:-360]
forKeyPath:@"transform.rotation.z"];
[UIView commitAnimations];
Upvotes: 0
Views: 3145
Reputation: 9977
Or just use M_PI directly.
M_PI_4
= 45 degreesM_PI_2
= 90 degreesM_PI
= 180 degrees M_PI*2
= 360 degreesYou can also set your transform more easily.
// set transform
splashView.layer.transform = CATransform3DMakeRotation(-M_PI*2, 0, 0, 1);
instead of
[splashView.layer setValue:[NSNumber numberWithInt:-360]
forKeyPath:@"transform.rotation.z"];
Upvotes: 1
Reputation: 8512
To rotate in specific direction more than 360°use CAKeyframeAnimation
. There you can set not only the final value, but also some intermediate values.
// consider this to be pseudo code
keyFrameAnimation.values = @[ 90, 180, 270, 360, 450, 540, ... ];
I don't have any code to show you, but this is defnitely the way to do it.
Upvotes: 1
Reputation: 130193
That's because you're passing degrees to the animation when it wants radians. Here's an example of how to make the conversion.
float degrees = 90.0f;
float radians = degrees * (180.0f / M_PI);
Upvotes: 0