iOS - 从底部填充 UIBezierPath 的动画

iOS - Fill Animation of a UIBezierPath from bottom

我在自定义 UIViewdraw() 中有一个 UIBezierPath。我想填充那条路径,假设是一个从下到上的矩形。我该如何实现它。

Here 我看到使用 CAShapeLayer 是可行的。这对于动画效果很好,但填充不是从矩形的底部到顶部发生的。请指导。

这是你要的吗?

func zoom() {
    let startPath = UIBezierPath(rect: CGRect(x: 0, y: self.frame.size.height-30, width: self.frame.size.width, height: 30))
    let endPath = UIBezierPath(rect: CGRect(x: 0, y: 0, width: self.frame.size.width, height: self.frame.size.height))

    let rectangleLayer = CAShapeLayer()
    rectangleLayer.path = startPath.cgPath
    rectangleLayer.fillColor = UIColor.cyan.cgColor
    self.layer.addSublayer(rectangleLayer)

    let zoomAnimation = CABasicAnimation()
    zoomAnimation.keyPath = "path"
    zoomAnimation.duration = 2.0
    zoomAnimation.toValue = endPath.cgPath
    zoomAnimation.fillMode = kCAFillModeForwards
    zoomAnimation.isRemovedOnCompletion = false
    rectangleLayer.add(zoomAnimation, forKey: "zoom")
}