rameezhandel / SmartGauge

Customizable Gauge View for iOS
MIT License
3 stars 2 forks source link

Want to animate smoothly of smart gauge view using Timer #6

Open ShahhPayal opened 3 months ago

ShahhPayal commented 3 months ago

I want to update gauge value with timer with smooth animation, currently the value is updated using Timer but the animation is not smooth, showing jerky animation. Is there any property like "gaugeView.setGaugeValue" instead "gaugeView.gaugeValue"?

Here is my code:

var timer = Timer()
    var speedTime : Int = 0
    {
        didSet
        {
            DispatchQueue.main.async {
                self.gaugeView.gaugeValue = CGFloat(CGFloat(self.speedTime))
            }
        }
    }

override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        setupGaugeView()
        timer = Timer.scheduledTimer(timeInterval: 0.1, target: self, selector: #selector(self.updateTimer), userInfo: nil, repeats: true)
    }

@objc func updateTimer() {
        if speedTime >= 80 {
            timer.invalidate()
        } else {
            speedTime += 1
        }
    }

Please help me and provide any solution for this. Thank you in advance.