我有一个旋转的动画,我希望该动画从轻按时的状态继续。为此,我尝试了以下代码:
if let presentation = plus.presentation() {
object.frame = presentation.frame
object.setValue(presentation.value(forKeyPath: animation.keyPath!), forKey: animation.keyPath!) // doesn't do much it seems
object.transform = presentation.transform
}
但是当再次轻按该对象时,它似乎从另一个锚点开始旋转:
func rotateObject() {
let animation = CABasicAnimation(keyPath: "transform.rotation")
animation.toValue = CGFloat.pi * 2
let curve = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
animation.timingFunction = curve
animation.duration = 1.5
if let presentation = plus.presentation() {
object.frame = presentation.frame
object.setValue(presentation.value(forKeyPath: animation.keyPath!), forKey: animation.keyPath!)
object.transform = presentation.transform
}
object.removeAllAnimations()
object.add(animation, forKey: animation.keyPath)
}
点击时,我应该使用什么来获取旋转状态?