我在自定义UIBezierPathUIView中有一个draw()。我要填充该路径,可以说是一个从下到上的矩形。我该如何实施。

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")
}

关于ios - iOS-从底部填充UIBezierPath的动画,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41464101/

10-10 21:05