如何捕捉形状图层中每个点绘制路径的瞬间?

时间:2019-01-07 14:40:07

标签: ios swift core-graphics

我要做的是:

let pathLayer = CAShapeLayer()

func drawBezierPath(from points: [CGPoint]) {
    let path = UIBezierPath()
    path.move(to: points.first!)
    points.forEach { path.addLine(to: $0) }
    pathLayer.path = path.cgPath

    CATransaction.begin()
    CATransaction.setCompletionBlock(block)
    let strokeEndAnimation = CABasicAnimation(keyPath: "strokeEnd")
    strokeEndAnimation.fromValue = 0
    strokeEndAnimation.toValue = 1
    let animation = CAAnimationGroup()
    animation.animations = [strokeEndAnimation]
    animation.duration = 1
    pathLayer.add(animation, forKey: "PathAnimation")
    CATransaction.commit()
}

问题是如何捕捉路径在屏幕上每个路径点的瞬间。为什么?我需要将滚动视图居中到当前点。我该怎么办?

0 个答案:

没有答案