更新开始
正确答案在这里:
Is it posible to do multiple animations on UIView without using completion block
无需阅读此内容。
更新结束
我和UIView animateWithDuration returns immediately有类似的问题,但我不能使用完成块,因为我的动画有不同的功能。
但是想要为同一个对象制作动画。
我正在制作纸牌游戏,所以我在屏幕上移动卡片,但是在移动的同时我也有一些游戏逻辑。这就是为什么我可以方便地单独制作动画。
如何解决这个问题?
@Fogmeister
完成问题如下:
在method1之后,调用方法2
如果我想调用method1 52次(因为我有52张牌),那么method2也会被调用52次
但在我的场景中,我需要跟随,调用方法1 52次,比调用方法2 4次...
所以我不知道这会如何在竞争中失败
有时我需要在method1之后调用method2,但有时我需要在method1之后调用method3 ...
我正在考虑在method1之后制作对象的深层副本,然后在新对象上调用method2 那会有用吗?
@Fogmeister第二回复
我也得出了同样的结论
但我不喜欢这两个原因
我需要将游戏逻辑放在动画逻辑中,我希望将事物松散耦合
动画代码不应该处理游戏逻辑代码。
我想要做的是做一个又一个相同的UIView对象的多个动画,而不使用完成:,因为我不会保持动画代码简单并重复使用它。
如果您需要,可以从中下载我的代码
http://weborcode.com/dl/Tablic.zip
动画在TBL_CardView.m文件方法动画*中完成
它来自:
TBL_GameViewController.m文件方法gameStateMachineLoop
所有牌都从左到右洗牌,然后再将一张牌发送到左边
但问题是,在洗牌之前,该卡已经在右侧,
如果您启动该项目,您将会看到它。
答案 0 :(得分:1)
还没有很多信息可以继续,但你不必为每个动画制作一件动画。如果您想为所有卡片制作动画,请使用单个动画并更新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
}
您所做的只是控制流量。不要再考虑在桌子周围移动卡片了,想一想你可以使用哪些工具以及如何使用它们来做你想做的事情。