iOS – 从底部填充UIBezierpath的animation

我有一个UIBezierPath自定义UIViewdraw() 。 我想填充这个path,让我们从下到上说一个矩形。 我怎样才能实现这一点。

从这里我已经看到使用CAShapeLayer它可能。 这是工作正常的animation,但填充不会发生在矩形上从下到上。 请指导。

这是你要求的吗?

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