如何对两个CABasicAnimation动画进行分组并在完全相同的时间将它们启动? [英] How to group two CABasicAnimation animations and kick them off at the exact same time?
问题描述
我知道核心动画中存在某种动画分组机制。所以可以说我有两个CABasicAnimation firstAnimation
和 secondAnimation
。我将如何对它们进行分组以及如何开始进行动画处理?
I know there is some kind of animation grouping mechanism in core animation. So lets say I have two CABasicAnimation firstAnimation
and secondAnimation
. How would I group these and how would I kick off the group to start animating?
推荐答案
您将要使用CAAnimationGroup类。创建一个包含所需动画的数组,然后将AnimationGroup的动画
属性设置为该数组。 CAAnimationGroup是CAAnimation的子类,因此您可以像常规动画一样使用 [layer addAnimation:forKey:]
将其添加到图层中。添加到图层后,组中的所有动画将同时执行。
You'll want to use the CAAnimationGroup class. Create an array containing the animations you want, and set the AnimationGroup's animations
property to that array. CAAnimationGroup is a subclass of CAAnimation, so you can add it to a layer using [layer addAnimation:forKey:]
like you would a regular animation. Once added to a layer, all animations in a group execute concurrently.
我建议阅读 CAAnimationGroup参考首先。在使用之前,有许多实现细节值得理解。例如:
I would suggest reading the CAAnimationGroup Reference first. There are a number of implementation details worth understanding before you use it. For example:
- 单个动画的
delegate
属性将被忽略。 - 单个动画的
removeOnCompletion
属性将被忽略。 - AnimationGroup具有自己的
委托
和removeOnCompletion
属性。 - 动画没有按时间缩放到该组,因此如果单个动画的持续时间长于组对象的持续时间,则会在组的持续时间结束时中断。
-
动画$ c复制并保留CAAnimationGroup的$ c>属性。
- The
delegate
property of individual animations is ignored. - The
removeOnCompletion
property of individual animations is ignored. - The AnimationGroup has its own
delegate
andremoveOnCompletion
properties. - Animations aren't time-scaled to the group, so if an individual animation has a duration longer than that of the group object, it will be interrupted at the end of the group's duration.
- The
animations
property of CAAnimationGroup is copied, not retained.
这篇关于如何对两个CABasicAnimation动画进行分组并在完全相同的时间将它们启动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!