I have a progress method here:
func progress(incremented : CGFloat){
if incremented <= self.bounds.width{
self.progressLayer.removeFromSuperlayer()
let originBezierPathProg = UIBezierPath(roundedRect: CGRect(x:0, y:0, width:0, height:self.bounds.height) , cornerRadius: self.viewCornerRadius)
originBezierPathProg.close()
let newBezierPathProg = UIBezierPath(roundedRect: CGRect(x:0, y:0, width:incremented, height:self.bounds.height) , cornerRadius: self.viewCornerRadius)
bezierPathProg.close()
self.progressLayer.path = originBezierPathProg.cgPath
self.borderLayer.addSublayer(self.progressLayer)
let animation = CABasicAnimation(keyPath: "path")
animation.fromValue = originBezierPathProg.cgPath
animation.toValue = newBezierPathProg.cgPath
animation.duration = 1
self.progressLayer.add(animation, forKey: animation.keyPath)
self.progressLayer.path = newBezierPathProg.cgPath
}
}
I am trying to make progress bar progress in an animated way. But when I call progress(100)
, it's simply rendering the bar without animation.
How can I fix it?
Update: Created MCVE as per Rob's suggestion: https://github.com/utkarsh2012/ProgressBarTest . I expect the progress bar to animate from width=0 to width=x (say 60)
Looks similar to this problem CABasicAnimation with CALayer path doesn't animate