简体   繁体   English

为什么我要使用 CAAnimationGroup?

[英]Why would I use an CAAnimationGroup?

I have trouble understanding apple's core animation (for iOS).我无法理解苹果的核心 animation(适用于 iOS)。 I am trying to animate the position and bounds of a layer concurrently (but with different timing functions).我正在尝试同时为position和图层bounds设置动画(但具有不同的计时功能)。

According to the documentation, a CAAnimationGroup allows multiple animations to be grouped and run concurrently.根据文档,CAAnimationGroup 允许对多个动画进行分组并同时运行。 But according to my (early) experiments this can also be accomplished by adding several animation objects to the target layer.但根据我的(早期)实验,这也可以通过向目标层添加几个 animation 对象来实现。 If so, what is the purpose of that CAAnimationGroup?如果是这样,那个 CAAnimationGroup 的目的是什么?

If you want to animate two different properties with different timing functions then grouping these animation is not needed in this case.如果您想使用不同的计时功能为两个不同的属性设置动画,那么在这种情况下不需要对这些 animation 进行分组。 I think that grouping is useful when you create several animations and want them to have the same timing behaviour.我认为当您创建多个动画并希望它们具有相同的计时行为时,分组很有用。 You can set timing function for the group.您可以为组设置时序 function。 In the Core Animation Cookbook i saw an example that shows how to use grouping when setting a timing curve for CAKeyframeAnimation.在 Core Animation Cookbook 中,我看到了一个示例,该示例显示了在为 CAKeyframeAnimation 设置时序曲线时如何使用分组。

The following quote is from the book "iOS Core Animation"以下引用来自《iOS Core Animation》一书

Adding an animation group to a layer is not fundamentally different from adding the animations individually, so it's not immediately clear when or why you would use this class.将 animation 组添加到层与单独添加动画没有根本区别,因此尚不清楚何时或为什么要使用此 class。 It provides some convenience in terms of being able to collectively set animation durations, or add and remove multiple animations from a layer with a single command, but it's usefulness only really becomes apparent when it comes to hierarchical timing, which is explained in Chapter 9.它提供了一些便利,可以集中设置 animation 持续时间,或者使用单个命令从层中添加和删除多个动画,但它的用处只有在涉及分层时序时才真正变得明显,这将在第 9 章中解释。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM