Sazzad Hissain Khan
Sazzad Hissain Khan

Reputation: 40136

iOS - Fill Animation of a UIBezierPath from bottom

I have a UIBezierPath inside custom UIView, draw(). I want to fill that path, lets say a rectangle from bottom to top. How can I implement this.

From Here I have seen using CAShapeLayer its possible. That is working fine with animation but filling is not happening from bottom to top on the rectangle. Please guide.

Upvotes: 3

Views: 1912

Answers (1)

Matt
Matt

Reputation: 1761

Is this what you are asking for?

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

Upvotes: 6

Related Questions