我玩弄了这个,我可以报告你是绝对正确的。它与零位夹紧无关。可见动画将在以下位置夹紧:
二者都
极端。
假设你提供了一个大的质量值,这样超调量应该远远超过凸弓的初始位置
返程
回到起点。然后我们看到的是动画夹钳
二者都
在原来的位置
和
至少要尝试将动画设置为。当弹簧在它们之间摆动时,我们看到动画在一个极端和另一个极端之间发生,但当它达到最大或最小值时,它只是夹在那里,直到它有时间摆动到最大程度并返回。
path
不喜欢弹跳动画。这一点也在会议上提出
CAShapeLayer path spring animation not 'overshooting'
以下是我使用的代码(基于您自己的代码):
@IBAction func animateArcPath() {
self.animate(to:-1, in:0.5, from:arcShapeLayer.path!)
}
func animate(to arc:CGFloat, in time:Double, from current:CGPath) {
let goal = configureArcPath(curvePercentage: arc)
let anim = CABasicAnimation(keyPath: "path")
anim.duration = time
anim.fromValue = current
anim.toValue = goal
anim.delegate = self
anim.setValue(arc, forKey: "arc")
anim.setValue(time, forKey: "time")
anim.setValue(goal, forKey: "pathh")
arcShapeLayer.add(anim, forKey: nil)
}
func animationDidStop(_ anim: CAAnimation, finished flag: Bool) {
if let arc = anim.value(forKey:"arc") as? CGFloat,
let time = anim.value(forKey:"time") as? Double,
let p = anim.value(forKey:"pathh") {
if time < 0.05 {
return
}
self.animate(to:arc*(-0.5), in:time*0.5, from:p as! CGPath)
}
}