Reputation: 12444
I am simply trying to spin a UIImageView 360 degrees clockwise using this:
#define DEGREES_TO_RADIANS(angle) (angle / 180.0 * M_PI)
and this
imageView.transform = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(360));
However imageView doesn't spin at all even those it is being called. Is there something wrong I am doing? I do not want to use CAAnimations so please don't recommend me to do so.
Thanks!
Upvotes: 0
Views: 1345
Reputation: 1556
Here is the code inspired by Tommy's answer.
I used
NSInteger step;
to keep track of current rotated degree of the image view.
- (void)startAnimation
{
[UIView animateWithDuration:0.5f
delay:0.0f
options:UIViewAnimationOptionCurveLinear
animations:^{
imageView.transform = CGAffineTransformMakeRotation(120 * step / 180.0f * M_PI);
}
completion:^(BOOL finished) {
step++;
// rotation completed, reset for the next round
if (step == 4){
step = 1;
}
// perform the next rotation animation
[self startAnimation];
}];
}
Upvotes: 0
Reputation: 2442
Perhaps because the transform isn't happening over a duration of time. It seems to me that as long as it isn't perceivable over time you may need to perform the transform or sequence of transforms over a fraction of time.
Upvotes: 0
Reputation: 100652
The problem is that Core Animation will apply animations by finding the most direct route from the current state to the new state. Rotation by 0 degrees is the same as rotation by 360 degrees so the most direct route to your final transform is to do absolutely nothing.
Two steps of 180 degrees would be problematic because there are two equally direct routes from 0 to 180 degrees and Core Animation could pick either. So you probably need to break your animation into three steps. Do the first with a UIViewAnimationOptionCurveEaseIn
, the second with UIViewAnimationOptionCurveLinear
and the final with UIViewAnimationOptionCurveEaseOut
.
Upvotes: 2