ImageView动画步骤

时间:2014-11-15 06:39:08

标签: ios animation uiimageview

我有一个小桌面游戏,除了向对手展示最后的动作外,它都已完成。

我想做的是:

第1步:隐藏所有部分

第2步:动画移动

第3步:再次显示现有作品

我尝试了什么,

[UIView animateWithDuration:5.00 delay:0.5
                        options:UIViewAnimationOptionCurveEaseOut //4
                     animations:^{

                         for (int i = 0; i<[_piecePlayer1 count]; i++) {
                         [[_piecePlayer1 objectAtIndex:i] hide];
                         [[_piecePlayer2 objectAtIndex:i] hide];

                         }


                     }
                     completion:^(BOOL finished){


}];

以这种方式隐藏。

-(void)hide{

    CATransition *animation = [CATransition animation];
    animation.type = kCATransitionFade;
    animation.duration = 0.4;
    [self.layer addAnimation:animation forKey:nil];

    self.hidden = YES;
}

问题:

第1步工作正常,但是如果我跳过第2步并尝试在completion block中显示片段,它就会立即出现,即使我已经放置了一个延迟的嵌套动画块。

我如何逐步实现这一点,在第一个动画完成后执行其他动画?

感谢danielquokka和 特别感谢这一个Repeat Animation

1 个答案:

答案 0 :(得分:1)

我认为核心问题是隐藏属性不可动画。而是使用alpha属性,可以设置动画。但我不明白你为什么要在这里使用CATransition。下面的代码会淡出碎片,短暂延迟,然后淡出它们。

[UIView animateWithDuration:5.00 
                      delay:0
                    options:UIViewAnimationOptionCurveEaseOut
                 animations:^{
                         for (int i = 0; i<[_piecePlayer1 count]; i++) {
                             _piecePlayer1[i].alpha = 0.0;
                             _piecePlayer2[i].alpha = 0.0;
                         }
                     }
                     completion:^(BOOL finished){
                        [UIView animateWithDuration:5.00 
                                              delay:0.5
                                            options:UIViewAnimationOptionCurveEaseIn
                                         animations:^{
                                                for (int i = 0; i<[_piecePlayer1 count]; i++) {
                                                    _piecePlayer1[i].alpha = 1.0;
                                                    _piecePlayer2[i].alpha = 1.0;
                                                }
                                            }
                                            completion:^(BOOL finished){}
                        }];

}];