1
votes

I'm using a Tab Bar Controller and a pod UICircularProgressRing to animate a timer, when I'm switching to first controller from Timer Controller and right back, animation in Timer Controller is instantly set to end. Is possible to run in background animation so when i switch back animation continue running like you just hide and unhide view ?

Here is a gif with issue.

via GIPHY

Edit 1

Here's a example how I want to get working https://giphy.com/gifs/ios-animation-timer-3ohzdGYkzbc1gjnUPe

1
Could you show some code?Kamil Harasimowicz
Here is just one line of code to start ring animation ring.setProgress(value: CGFloat(10), animationDuration: TimeInterval(10))lightofsky
Where you add this line?Kamil Harasimowicz
In viewDidAppear in TimerController. Link to project github.com/cpd/liblightofsky

1 Answers

0
votes

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.