An unnecessary complication is introduced in the keyframe animation. Just rotate the label around the center with the same duration as the dash layer animation:
![enter image description here](https://fooobar.com/undefined)
(I apologize that my animation starts at the bottom, not the top, but I did not consider your question when I wrote the code, and now I'm too lazy to change it!)
So how is this done? These are three animations, all with the same duration:
The strokeEnd
form level is strokeEnd
like your animation.
A “hand” passing through the center of the circle, with the label as a sublayer at one end (so that the label appears in the radius of the circle). Hand makes rotation transformation animation.
The label makes the animation of the rotation transformation in the opposite direction. If he didn’t, he would spin with his superlayer. (Think about how the Ferris wheel works, your chair is at the end of the arm, but it remains vertical to the ground.)
This is all the animation code:
let anim = CABasicAnimation(keyPath: "transform.rotation.z") anim.fromValue = 0 anim.toValue = 5 anim.duration = 10 self.arm.layer.add(anim, forKey:nil) let anim2 = CABasicAnimation(keyPath: "transform.rotation.z") anim2.fromValue = 0 anim2.toValue = -5 anim2.duration = 10 self.lab.layer.add(anim2, forKey:nil) let anim3 = CABasicAnimation(keyPath: "strokeEnd") anim3.fromValue = 0 anim3.toValue = 1 anim3.duration = 10 self.shape.add(anim3, forKey:nil)
source share