如何做一个可重复嵌套的UIView动画?

时间:2011-08-18 12:11:18

标签: iphone objective-c animation uiview repeat

我需要动画鸟类动画,其中鸟类图像以小像素出现,然后生长并移动到动画的中点。之后,鸟缩小回小像素,但向前移动直到达到终点。我需要这个动画是可重复的。我用两个动画做到了这一点:第一个增长图像并移动,在完整的块中,第二个缩小和移动。第一个动画有重复选项,即recond beginFromCurrentState。问题是从未调用过完整的块。我错过了什么,也许完整的块不适用于可重复的动画?这是我的代码:

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

    }}];        
}}];  

1 个答案:

答案 0 :(得分:4)

如果父动画无限期重复,因为你设置UIViewAnimationOptionRepeat,它永远不会调用完成块,因为它永远不会完成。就这么简单。