dev6546
dev6546

Reputation: 1442

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

Upvotes: 0

Views: 1124

Answers (1)

dev6546
dev6546

Reputation: 1442

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"];

Upvotes: 7

Related Questions