Justine
Justine

Reputation: 381

iOS UIView animation (animationWithDuration:) with multiple options

I'm trying to implement a UIView animation block with animationWithDuration and multiple options. It is working fine except it only seems to use one of the options I specify instead of all three. Is there a limit to the number of options I can specify or a limit on certain combinations of options?

Below is my code. "starRotator" is a UIImageView in a UIView that I'm rotating. I tried wrapping the options in parentheses, but that didn't work either. It seems to only take the UIViewAnimationOptionRepeat option and ignore the other two.

[UIView animateWithDuration:30.0 
                      delay:0.0 
                    options:UIViewAnimationCurveLinear | UIViewAnimationOptionRepeat | UIViewAnimationOptionBeginFromCurrentState
                 animations:^{
                     starRotator.superview.transform = CGAffineTransformMakeRotation(M_PI);
                 }
                 completion:^(BOOL finished){ }
 ];

Upvotes: 4

Views: 4752

Answers (2)

Matt Wilding
Matt Wilding

Reputation: 20163

That code is fine, except that you want to use UIViewAnimationOptionCurveLinear instead of UIViewAnimationCurveLinear. The latter is for use with UIView's old +setAnimationCurve: method.

Try changing that and see if you have any more luck.

Upvotes: 2

rob mayoff
rob mayoff

Reputation: 385920

Did you notice that two of the constants you're using as options contain the word “Option”, but one doesn't?

The correct option constant for a linear curve is UIViewAnimationOptionCurveLinear, but you used UIViewAnimationCurveLinear.

Upvotes: 5

Related Questions