开发者

How to do a repeatable nested UIView animation?

开发者 https://www.devze.com 2023-03-29 03:57 出处:网络
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 forwar

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 poin开发者_StackOverflow中文版t 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];

    }}];        
}}];  


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号