我在CAShapeLayer中使用CAAnimation來簡單地爲從左到右描邊的線條(它只是一個更復雜的程序的簡化版本)設置動畫。我放慢了速度,以顯示第一季度幾乎是瞬間的,然後其餘的正常動畫。如何在CAAnimation中使用UIViewAnimationCurve選項
我看到,可以使用UIView.animate的選項來設置UIViewAnimationCurve選項(例如,.EaseIn或.Linear)。在CAShapeLayer中嵌入CAAnimation時可以設置這些選項嗎?是否有必要在每次運行它時創建動畫,或者是否存在「運行動畫」命令?
下面是我截下來代碼:
// the containing UIView is called mainView
mainView.layer.sublayers = nil
// create a line using a UIBezierPath
let path = UIBezierPath()
path.move(to: CGPoint(x: 100, y: 100))
path.addLine(to: CGPoint(x: 300, y: 100))
// create a CAShapeLayer
let shapeLayer = CAShapeLayer()
shapeLayer.frame = CGRect(x: 0, y: 0, width: 1024, height: 1024)
shapeLayer.strokeColor = UIColor.green.cgColor
shapeLayer.lineWidth = 100
shapeLayer.path = path.cgPath
// create the animation
mainView.layer.addSublayer(shapeLayer)
let animation = CABasicAnimation(keyPath: "LetterStroke")
animation.fromValue = 0
animation.toValue = 1
animation.duration = 10
shapeLayer.add(animation, forKey: "animation")
提前非常感謝。
這是正確的答案,非常感謝。實際上,我發現問題存在於其他地方,正如你可以在下面看到的,但事實上,你確實按照陳述回答了我的問題。 –