我创造了一个财富之轮,我很难阻止它。 如何平滑地停止用户启动的,手势控制的圆形物体运动。我能够突然停止对象,但希望能够逐渐顺利停止。
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")
答案 0 :(得分:1)
变化
spinAnimation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
要
spinAnimation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut)
随着时间的推移,缓出应该会减慢动画效果。有关计时的详细信息,请参阅https://developer.apple.com/library/mac/documentation/Cocoa/Reference/CAMediaTimingFunction_class/#//apple_ref/doc/constant_group/Predefined_Timing_Functions