如何在iPhone-OS中链接动画? [英] How can I chain animations in iPhone-OS?

查看:103
本文介绍了如何在iPhone-OS中链接动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做一些复杂的动画。但我只知道如何动画一个块的变化。是否有链接动画的方法,以便我可以例如进行更改A - > B - > C - > D - > E - > F(等等),而核心动画等待,直到每个动画完成,然后继续下一个?

I want to do some sophisticated animations. But I only know how to animate a block of changes. Is there a way to chain animations, so that I could for example make changes A -> B -> C -> D -> E -> F (and so on), while the core-animation waits until each animation has finished and then proceeds to the next one?

特别是,我想这样做:我有一个UIImageView显示一个多维数据集。

In particular, I want to do this: I have an UIImageView that shows a cube.

阶段1)立方体在地板上平坦

Phase 1) Cube is flat on the floor

阶段2)立方体向左轻微旋转,而旋转原点在左下方。

Phase 2) Cube rotates slightly to left, while the rotation origin is in bottom left.

阶段3)立方体向右轻微旋转,而旋转原点在右下方。

Phase 3) Cube rotates slightly to right, while the rotation origin is in the bottom right.

这些阶段重复10次,并在阶段1停止)。

These phases repeat 10 times, and stop at Phase 1). Also, the wiggling becomes lesser with time.

我知道如何对一个块中的一个变化进行动画处理,但是我如何使用一些复杂的代码之间?这是不一样的事情随着时间的推移。

I know how to animate ONE change in a block, but how could I do such a repeating-thing with some sophisticated code in between? It's not the same thing over time. It changes, since the wiggling becomes lesser and lesser until it stops.

推荐答案

假设你正在使用UIView动画...

Assuming you're using UIView animation...

您可以提供一个动画stopped方法,当动画实际完成时调用(检出 setAnimationDelegate ) 。所以你可以有一个动画排队排队,准备去。设置委托,然后开始第一个动画。当它结束时,它调用 setAnimationDidStopSelector 方法(确保检查完成标志,以确保它真的完成,而不是刚暂停)。你也可以传递一个动画上下文,它可以是动画队列中的索引。它也可以是一个包含计数器的数据结构,因此您可以通过每个周期调整动画值。

You can provide an animation 'stopped' method that gets called when an animation is actually finished (check out setAnimationDelegate). So you can have an array of animations queued up and ready to go. Set the delegate then kick off the first animation. When it ends it calls the setAnimationDidStopSelector method (making sure to check the finished flag to make sure it's really done and not just paused). You can also pass along an animation context which could be the index in your queue of animations. It can also be a data structure that contains counters so you can adjust the animation values through each cycle.

因此,这只是一个等待完成的事

So then it's just a matter of waiting for one to be done then kicking off the next one taken off the queue.

如果您使用其他类型的动画,同样的方法也适用。你只需要设置你的数据结构,使它知道在每一个结束后做什么。

The same method applies if you're using other types of animation. You just need to set up your data structures so it knows what to do after each one ends.

这篇关于如何在iPhone-OS中链接动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆