0

I need to animate bird fly where the bird image appears with as small pixel, then grows and moves until middle point of the animation. After that the bird shrinks back to small pixels but moves forwardly till end point is reached. And I need this animation to be repeatable. I did that with two animations: the first that grows the image and moves and, in the complete block, the second one that shrinks and moves. The first one animation has repeat option, the recond beginFromCurrentState. The problem is the complete block has never been called. What am I missing, maybe complete block doesn't work for repeatable animations? Here is my code:

[UIView animateWithDuration:4.0 delay:0 options:(UIViewAnimationCurveEaseIn | UIViewAnimationOptionRepeat | UIViewAnimationOptionAllowUserInteraction) animations:^{
    self.bird1.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1, 1);
    self.bird1.center = bird1MiddlePoint;

} completion:^(BOOL finished){if (finished){

    NSLog(@"doesn't get called");
    [UIView animateWithDuration:4.0 delay:0 options:(UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionAllowUserInteraction) animations:^{

        self.bird1.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.1, 0.1);
        self.bird1.center = bird1EndPoint;} completion:^(BOOL finished){if (finished && !self.gameManager.isPlaying){

            [UIView setAnimationRepeatCount:0];
            [self.bird1 removeFromSuperview];

    }}];        
}}];  
Centurion
  • 14,106
  • 31
  • 105
  • 197

1 Answers1

4

If the parent animation is repeating indefinitely, since you set UIViewAnimationOptionRepeat, its never going to call the completion block because its never finishes. It's as simple as that.

MiguelB
  • 1,913
  • 18
  • 20
  • It would be more logical if complete block would work even for repeating animations ;) Because there is no possibility to nest inner animations now (at least with UIView animations) – Centurion Aug 18 '11 at 14:00
  • 1
    I have a friend called CAKeyframeAnimation. I think you should meet him. – MiguelB Aug 18 '11 at 14:09
  • By the way, there are workarounds to UIView animation blocks using the delay option, so that you don't have to use the completion block, but I wouldn't recommend doing it, especially if you are animating the same properties consecutively. – MiguelB Aug 18 '11 at 14:11
  • 1
    There is something else you can do, just came to mind. You would have to place the whole animation code stashed independently in some "animation method". You could nest the animations the same way you were doing, however without using the `UIViewAnimationOptionRepeat`, so that the whole animation just runs once per call. Then, in the last completion block you make a call to the animation method, so that it runs recursively. – MiguelB Aug 18 '11 at 14:40
  • Thanks. Actually, I have tried recursive calls already but got some flashings between 2-3 animation: http://stackoverflow.com/questions/6766955/how-to-have-a-handler-to-repeat-uiview-animatewithduration – Centurion Aug 18 '11 at 15:05