簡體   English   中英

如何做可重復的嵌套UIView動畫?

[英]How to do a repeatable nested UIView animation?

我需要給小鳥動畫,使小鳥圖像以小像素出現,然后生長並移動到動畫的中點。 之后,小鳥縮小到小像素,但向前移動直到到達終點。 而且我需要這種動畫是可重復的。 我用兩個動畫來做到這一點:第一個動畫增加圖像並移動,而在整個塊中,第二個動畫收縮並移動。 第一個動畫具有重復選項,即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];

    }}];        
}}];  

如果父動畫無限期重復,則因為您設置了UIViewAnimationOptionRepeat ,所以它永遠不會調用完成塊,因為它永遠不會結束。 就這么簡單。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM