0
我创造了一个幸运之轮,我无法阻止它。 我该如何平稳地停止用户发起的,手势控制的运动中的圆形对象。我能够突然停止对象,但希望逐渐平稳地停下来。如何顺利暂停动画?
let spinAnimation = CABasicAnimation()
spinAnimation.fromValue = 0
// goes to 360 (2 * π)
spinAnimation.toValue = M_PI*2
// define how long it will take to complete a 360
spinAnimation.duration = 10
// make it spin infinitely
spinAnimation.repeatCount = Float.infinity
// do not remove when completed
spinAnimation.removedOnCompletion = false
// specify the fill mode
spinAnimation.fillMode = kCAFillModeForwards
// and the animation acceleration
spinAnimation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
counterView.layer.backgroundColor = UIColor.redColor().CGColor
// add the animation to the button layer
counterView.layer.addAnimation(spinAnimation, forKey: "transform.rotation.z")
它的任何示例?我试图让车轮停下来,但不能回到起点。 – Peter
然后不要做'M_PI * 2'的值,而是'M_PI *基于随机或强制的某个数字'确保随机数是一个小数,否则你只会做180 – Knight0fDragon