Working code:
import UIKit
import UICircularProgressRing
class TimerCountdownViewController: UIViewController {
@IBOutlet weak var ring: UICircularProgressRingView!
var currentValue: CGFloat?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
ring.setProgress(value: currentValue ?? 0, animationDuration: 0.0) { [weak self] in
self?.ring.setProgress(value: 10.0, animationDuration: 8.0)
}
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
currentValue = ring.currentValue
}
}
I discovered that every time vc will disappear UICircularProgressRing
pod marks ring
as completed. The trick is I save currentValue
every time I leave vc. After come back to vc I set progress of ring to old value and after that I continue progress to maxValue.
You could work on animationDuration
when currentValue is coming to maxValue to make animation more smoothly.
ring.setProgress(value: CGFloat(10), animationDuration: TimeInterval(10))
– lightofsky