How to group two CABasicAnimation animations and kick them off at the exact same time?

六眼飞鱼酱① 提交于 2019-12-10 15:29:05

问题


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?


回答1:


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.

I would suggest reading the CAAnimationGroup Reference first. There are a number of implementation details worth understanding before you use it. For example:

  1. The delegate property of individual animations is ignored.
  2. The removeOnCompletion property of individual animations is ignored.
  3. The AnimationGroup has its own delegate and removeOnCompletion properties.
  4. 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.
  5. The animations property of CAAnimationGroup is copied, not retained.


来源:https://stackoverflow.com/questions/2892883/how-to-group-two-cabasicanimation-animations-and-kick-them-off-at-the-exact-same

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!