Call a method every time animation repeats

209 views Asked by At

I need to call a certain method before my animation repeats. I don't know where to place that line of code.

This is my code for animating an object:

[UIView animateWithDuration:speed
                      delay:delay
                    options:UIViewAnimationOptionAllowUserInteraction|UIViewAnimationOptionCurveLinear|UIViewAnimationOptionRepeat
                 animations:^(void){

                     cloud.frame = (CGRectMake(cloud.frame.origin.x, cloud.frame.origin.y+600, cloud.frame.size.width, cloud.frame.size.height));

                 }completion:^(BOOL finished){
                     if (finished){
                         [cloud setBackgroundImage:[UIImage imageNamed:@"cloudWhite.png"] forState:UIControlStateNormal];
                     }
                 }];

Method called in completion part will not be executed before every repeat but only after whole animation is complete, together with al repeats - which is, in this case - never.

My question is, how to call a method before every animation repeat?

1

There are 1 answers

0
Duncan C On BEST ANSWER

I would suggest refactoring your animation so it does not use UIViewAnimationOptionRepeat. Instead, write a method that executes a single cycle of your animation. Then add a completion method block that calls the method recursively.

You can also put the method call that you want to fire on each iteration of your animation in the completion block.