kentya6 / KYCircularProgress

Flexible progress bar written in Swift.
MIT License
1.15k stars 115 forks source link

Isn't there anyway not to reset when it reached 100% #20

Closed sigmo2nd closed 7 years ago

sigmo2nd commented 7 years ago

Sorry, there is no such place that I could ask about this. so I post it here.

I would like to show various data through this framework, however it keeps being reset.

on my project I used timer.scheduled to get some animation. there is 2 integers I have set

for example

private var progress: UInt8 = 0 var totalAmount:Int = 28000 var paidAmount:Int = 8000 @IBOutlet private weak var storyboardCircularProgress1: KYCircularProgress! @IBOutlet private weak var progressLabel: UILabel!

override func viewDidLoad() {
    super.viewDidLoad()

    configureStoryboardProgress1()
    updateProgress()
}

private func configureStoryboardProgress1() {
    storyboardCircularProgress1.colors = [.purple, .purple, .purple]
    storyboardCircularProgress1.progressChanged {
        (progress: Double, circularProgress: KYCircularProgress) in
        self.progressLabel.text = String.init(format: "%.0f", progress * 100.0) + "%"
    }
    storyboardCircularProgress1.
}

@objc private func updateProgress() {
    progress = progress &+ 2
    let normalizedProgress = Double(progress) / Double(UInt8.max)
    storyboardCircularProgress1.progress = normalizedProgress
    if progress == 255
    {

    }
    if progress < UInt8(Double(paidAmount) / Double(totalAmount) * 255)
    {
        self.addTime()
    }
}

func addTime()
{
    Timer.scheduledTimer(timeInterval: 0.01, target: self, selector: #selector(updateProgress), userInfo: nil, repeats: false)
}

}

the animation showed 30% whiles it's about 29.6% that's great however, when I set

var totalAmount:Int = 28000 var paidAmount:Int = 0

the result will be 1% that's weird and also

var totalAmount:Int = 28000 var paidAmount:Int = 28000

then the result keeps being reset and animation goes forever like your demo. I really wish that I could use the framework for my project, it's really simple and nice but I'm not capable enough to fix this problem. Hope you could kindly guide me to right path.

Thanks million in advance.

sigmo2nd commented 7 years ago

Sorry my fault :( I figured it out by myself.