我创造了一个命运之轮,但我无法阻止它。
如何平稳地停止用户启动的,手势控制的圆形物体运动。我能够突然停止该对象,但希望有一个平稳的停止过程。

   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")

最佳答案

更改
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

10-08 07:27