I have defined a CAKeyframeAnimation
to rotate a CALayer
along z axis. For the animation to work, I've used the values
, keyTimes
and duration
properties of the animation object.
Below is what I've:
let rotationInDegrees: CGFloat = 7 * 360.0 // 7 times full rotation
let transformationAnimation = CAKeyframeAnimation(keyPath: "transform.rotation.z")
transformationAnimation.values = [0, rotationInDegrees * (CGFloat.pi / 180)]
transformationAnimation.keyTimes = [0, 1]
transformationAnimation.duration = 15
myLayer.add(transformationAnimation, forKey:"transformationAnimation")
Now I need to perform some other tasks when the layer rotates to every x
degrees. I can't find a way for my cause.
What do I need to do to be notified of every x
degrees change in the rotation?
I've tried KVO for value observation like:
token = transformationAnimation.observe(\.values) { (anim, values) in
print(anim.values)
}
The observation block never gets triggered.
Also tried similar approach answered in this question. But seems that the solutions provided there only work for "progress"
key not for "transform.rotation.z"
(also tried with "transform"
/ "transform.rotation"
key names but they don't also work. Even "transform"
emits values for progress ranging 0.0 ~ 1.0).
None of the above tries seem to work.