How to group two CABasicAnimation animations and run them at the same time?

I know that in the main animation there is some kind of animation grouping mechanism. So let's say I have two CABasicAnimation firstAnimation and secondAnimation . How would I group them and how would I start a group to start an animation?

+4
source share
1 answer

You want to use the CAAnimationGroup class. Create an array containing the desired animations, and set the AnimationGroup animations property for this array. CAAnimationGroup is a subclass of CAAnimation, so you can add it to a layer using [layer addAnimation:forKey:] , as you would for a normal animation. After adding to a layer, all animations in the group are performed simultaneously.

I would suggest reading the CAAnimationGroup Reference first . Before using it, you need to know a number of implementation details. For instance:

  • The delegate property of individual animations is ignored.
  • The removeOnCompletion property of individual animations is ignored.
  • AnimationGroup has its own delegate and removeOnCompletion .
  • An animation is not time bound to a group, therefore, if an individual animation has a duration longer than that of a group object, it will be interrupted at the end of the group duration.
  • The animations property of the CAAnimationGroup file is copied, not saved.
+6
source

Source: https://habr.com/ru/post/1310666/


All Articles