Question

I am using following code to full rotate image for clockwise

       - (void) runSpinAnimationOnView:(UIView*)view duration:(CGFloat)duration         rotations:      (CGFloat)rotations repeat:(float)repeat;
  {
   CABasicAnimation* rotationAnimation;
   rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
       rotationAnimation.toValue = [NSNumber numberWithFloat: rotations * 2.0 /* full rotation*/ * rotations * duration ];
    rotationAnimation.duration = duration;
    rotationAnimation.cumulative = YES;
    rotationAnimation.repeatCount = repeat;
    [view.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
    } 

and Calling it

          [self runSpinAnimationOnView:_cycleImage duration:0.1 rotations:M_PI_2 repeat:13];

it rotates the image clockwise and locks great , but How can rotate the same image and same animation and duration anti-clockwise. Please help

Was it helpful?

Solution

For an anti-clockwise rotation, set rotationAnimation.toValue to a negative value, for example

rotationAnimation.toValue = @(-2.0*M_PI);

for one full anti-clockwise rotation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top