我在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")
提前非常感谢。
这是正确的答案,非常感谢。实际上,我发现问题存在于其他地方,正如你可以在下面看到的,但事实上,你确实按照陈述回答了我的问题。 –