Search code examples
objective-crotationcore-animationpi

Creating a constant spinning UIImageView


I've tried using core animations like this:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    [UIView animateWithDuration:2.0 delay:0.0 options:UIViewAnimationOptionRepeat | UIViewAnimationOptionCurveLinear animations:^{ CGAffineTransform transform = CGAffineTransformMakeRotation(3.14);
        self->inner.transform = transform;
    } completion:NULL];
}

This spins my UIImageView called outer, but it doesn't complete the 360 degree spin im after smoothly. It jumps after its 3/4 or so the way round. Should I not be rotating on PI?

If I want to change the direction of the rotation how could I do that? It rotates clockwise at the minute.

Thanks


Solution

  • If anyone else needs this at any point:

    //outer ring
    CABasicAnimation *fullRotationAnimation;
    fullRotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    fullRotationAnimation.fromValue = [NSNumber numberWithFloat:0.0f];
    fullRotationAnimation.toValue = [NSNumber numberWithFloat:2 * M_PI];
    fullRotationAnimation.duration = 4;
    fullRotationAnimation.repeatCount = 5000;
    //fullRotationAnimation.cumulative = YES;
    [self->outer.layer addAnimation:fullRotationAnimation forKey:@"360"];