调用多个动画,一个接一个同一个UIView对象,不使用completion



update start

正确答案在这里:
有没有可能在UIView上做多个动画而不使用完成块

不需要读这个

<<p> UPATE结束/strong>

我有类似的问题作为UIView animateWithDuration立即返回,但我不能使用完成块,因为我的动画是在不同的功能。

但是想要动画相同的对象。

我正在制作纸牌游戏,所以我在屏幕上移动纸牌,但在移动之间我也有一些游戏逻辑。这就是为什么我把动画分开来做比较方便。

如何解决这个问题?

@Fogmeister
完成的问题如下:
在method1之后,调用method2。
如果我想调用method1 52次(因为我有52张牌),那么method2也将被调用52次。
但在我的情况下,我需要以下,调用method1 52次,调用method2 4次…
所以我不认为这与竞争有关。
有时我需要在method1之后调用method2,但有时我需要在method1之后调用method3…

我想在method1之后对对象进行深度复制,然后在新对象上调用method2。
这样行吗?

@Fogmeister第二次回应
我也得出了同样的结论。但是我不喜欢它,原因如下。我需要把游戏逻辑放在动画逻辑中,我希望事情是松散耦合的。动画代码不应该处理游戏逻辑代码。

我想做的是做多个动画,一个接一个的同一个UIView对象,不使用completion:,因为我想保持动画代码简单,并重用它

如果你愿意,你可以从
下载我的代码http://weborcode.com/dl/Tablic.zip
动画在TBL_CardView中完成。M文件方法动画*
它被称为from:
TBL_GameViewController。m文件方法gamestatemachinelloop所有的牌从左向右洗牌,然后再将一张牌送到左边。
但问题是这张牌在洗牌前就已经在右边了,

没有太多的信息可以继续,但你不必每个动画一个东西。如果你想动画所有的卡,那么使用一个动画,并更新animations块中的所有的卡。

如果你想让所有的卡片都有动画效果然后你可以这样做。

- (void)animateCards:(NSArray *)cards
{
    // call this once and all of the cards in the array will animate over 5 seconds.
    [UIView animateWithDuration:5.0
                     animations:^{
                         for (Card *card in cards) {
                             card.frame = // whatever
                         }
                     }
                     completion:^(BOOL finished) {
                         if (iNeedToCallMethod2) {
                             [self doSomethingElse];
                         } else {
                             [self somethingCompletelyDifferent];
                         }
                     }];
}
- (void)doSomethingElse
{
    //this will only run after all the cards have animated
    //if the condition requires it to run
    [UIView animateWithDuration:5.0
                     animations:^{
                         for (Suit *suit in self.suits) {
                             // not really sure what you want to do here
                             // but you can do the same as above
                         }
                     }
                     completion:^(BOOL finished) {
                     }];
}
- (void)somethingCompletelyDifferent
{
    //this will run once only if the other method doesn't run
}

你所做的就是控制流。不要想着在桌子上移动卡片,多想想你有什么可用的工具,以及如何使用它们来做你想做的事情。

最新更新