我要做的是:
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()
}
问题是如何捕捉路径在屏幕上每个路径点的瞬间。为什么?我需要将滚动视图居中到当前点。我该怎么办?