Iphone 嵌套数量未知的UIView动画

Iphone 嵌套数量未知的UIView动画,iphone,ios,cocoa,Iphone,Ios,Cocoa,我正在制作一款iPhone纸牌游戏,我想在每一轮结束时将玩家的纸牌制作成动画。玩家在每轮结束时可以有任意数量的牌,所以我不能以任何静态方式嵌套动画代码。如果我有下面的代码来设置两个卡片视图对象的动画,那么 UICardView * __block card1 = [[UICardView alloc] init]; UICardView * __block card2 = [[UICardView alloc] init]; [UIView animateWithDuration:1.0f

我正在制作一款iPhone纸牌游戏,我想在每一轮结束时将玩家的纸牌制作成动画。玩家在每轮结束时可以有任意数量的牌,所以我不能以任何静态方式嵌套动画代码。如果我有下面的代码来设置两个卡片视图对象的动画,那么

UICardView * __block card1 = [[UICardView alloc] init];
UICardView * __block card2 = [[UICardView alloc] init];
[UIView animateWithDuration:1.0f 
                      delay:0.0f 
                    options:UIViewAnimationCurveLinear 
                 animations:^{
                                card1.frame = CGRectOffset(cardView.frame, 0.0f, -300.0f);
                             } 
                 completion:^(BOOL finished) {
                                [UIView animateWithDuration:1.0f
                                                      delay:0.0f 
                                                    options:UIViewAnimationCurveLinear 
                                                 animations:^{
                                                                 card2.frame = CGRectOffset(cardView.frame, 0.0f, -300.0f);
                                                             } 
                                                 completion:nil]
                 }];
…我如何构造代码,以设置位于已删除列表中的未知数量的卡片视图对象的动画


非常感谢你的智慧

…或者递归,也许:

- (void)animateCardNTimes:(int)times
{
    if (times <= 0) return;

    __block CardView *cv = [[CardView alloc] init]; 
    [UIView animateWithDuration:1.0f 
                          delay:0.0f 
                         options:UIViewAnimationCurveLinear 
                      animations:^{
                          cv.frame = CGRectOffset(cardView.frame, 0.0f, -300.0f);
                      } 
                      completion:^(BOOL finished) {
                          [self animateCardNTimes:times - 1];
                      }
    ];
}
-(无效)animateCardTimes:(int)次
{
如果(次)
您可以使用UICardView数组调用animateCards。(确保创建副本,因为数组最后将为空)

例如,如果你有一个self.playerCards作为一个UICardView数组,你想制作动画,就这样调用它

NSMutableArray *cardsToBeAnimated = [NSMutableArray arrayWithArray:self.playerCards];
[self animateCards:cardsToBeAnimated];

也许对
循环使用一个
?@H2CO3你能详细说明一下,或者给我一个例子吗?而不是递归,请看我的答案。
NSMutableArray *cardsToBeAnimated = [NSMutableArray arrayWithArray:self.playerCards];
[self animateCards:cardsToBeAnimated];