【发布时间】:2017-10-10 10:10:43
【问题描述】:
我在 CAShapeLayer 中使用 CAAnimation 来简单地对从左到右的线条进行动画处理(它只是一个更复杂程序的缩减版)。我已经放慢了速度,以表明开始的四分之一几乎是瞬间的,然后其余的动画正常。
我已经看到可以使用 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")
非常感谢。
【问题讨论】:
标签: ios swift3 caanimation