我让那个有生命的人。所以我有 headAnimation
、eyeAnimation
、earAnimation
、bodyAnimation
的方法。
当我调用所有动画时,我有方法 myAnimation
。
在该方法中,我需要延迟调用动画。如何在不使用 NSTimer
和 performSelector
的情况下做到这一点。
动画可以是平行的,也可以是串联的。那么我如何制作动画或 block 队列,我可以在哪里发送延迟以及调用什么方法?
编辑
我使用了[self performSelector:@selector(eyeAnimation) withObject:nil afterDelay: 2.0]
。并且对于每个方法动画 performSelector
。
在所有动画中,例如eye
:
我使用 [UIView animateWithDuration:duration
延迟:延迟选项:UIViewAnimationOptionCurveEaseInOut
动画:完成:];
。
所以现在在我的 -(void)myAnimation
10 performSelector
中有不同的延迟。
所以问题是我如何执行此操作。
编辑 #2
[UIView animateWithDuration:0.0 delay:2 options:UIViewAnimationOptionCurveEaseInOut animations:^{
[self eyeAnimation];
} completion:^(BOOL finished) {
if (finished) {
[UIView animateWithDuration:0.0 delay:8 options:UIViewAnimationOptionCurveEaseInOut animations:^{
[self earAnimation];
} completion:^(BOOL finished) {
}];
[UIView animateWithDuration:0.0 delay:17 options:UIViewAnimationOptionCurveEaseInOut animations:^{
[self bodyAnimation];
} completion:^(BOOL finished) {
}];
}
}];
但是当我调用 performSelector
时动画会有所不同。它们不是平行的。
最佳答案
我不明白你是如何结合上面这两种方法的,因为你使用的是 [UIView animateWithDuration:duration delay:delay options:UIViewAnimationOptionCurveEaseInOut animations: completion:];
我不知道为什么使用 [self performSelector:@selector(eyeAnimation) withObject:nil afterDelay: 2.0]
。
无论如何,对于我在与您的类似上下文中使用的应用程序,我都使用了使用的方法
[UIView animateWithDuration:delay:options:animations:completion:];
有了用于所需动画的 block 并在完成 block 中,我有了下一步需要完成的逻辑,这就是我链接动画并将它们按持续时间和延迟的正确顺序放置的地方。
这很好用,但如果你有大约 10 个动画,就像你说的那样。如果计划增加这个数字,最好打开一些游戏引擎来制作更复杂的动画,因为同步所有动画会让你迷失方向。
编辑
正如您在第二次编辑中编写的代码,所有动画的持续时间均为 0。第一个动画将在 2 秒后发生,之后第二个和第三个动画将被并行调用,但有它们的延迟,即第二个动画将在 10 秒后发生,第三个动画将在 19 秒后发生。
你期望什么?
关于ios - 创建动画队列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18914404/