【发布时间】:2020-07-09 11:57:35
【问题描述】:
我定义了一个CAKeyframeAnimation 来沿z 轴旋转一个CALayer。为了使动画正常工作,我使用了动画对象的values、keyTimes 和duration 属性。
以下是我的:
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")
现在我需要在图层旋转到每x 度时执行一些其他任务。我找不到我的事业的方法。
我需要做什么才能在旋转中的每个x 度变化时收到通知?
我尝试过使用 KVO 进行价值观察,例如:
token = transformationAnimation.observe(\.values) { (anim, values) in
print(anim.values)
}
观察块永远不会被触发。
也尝试过类似的方法回答in this question。但似乎那里提供的解决方案只适用于"progress" 键而不适用于"transform.rotation.z"(也尝试使用"transform" / "transform.rotation" 键名,但它们也不起作用。即使"transform" 发出0.0 范围内的进度值~ 1.0)。
上述尝试似乎都不起作用。
【问题讨论】:
标签: swift calayer caanimation cakeyframeanimation