[英]Smoothly pause a repeating UIView block animation on alpha before another animation
[英]How to pause animation smoothly?
我創造了一個命運之輪,但我無法阻止它。 如何平穩地停止用戶啟動的,手勢控制的圓形物體運動。 我能夠突然停止該對象,但希望有一個平穩的停止過程。
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.