0

As described in the title, I wanted to change a double variable (a property of the class) from to 0.0 to 1.0. Because I wanted achieve an animation effect with the DACircularProgressView, and I wrote the code for it:

func showProgressView() {
    progressView = DACircularProgressView(frame: CGRectMake(UIScreen.mainScreen().bounds.width - 60, 20, 40, 40))
    if let progressView = progressView {
        progressView.progress = 0
        addSubview(progressView)
        UIView.animateWithDuration(3, animations: { 
            progressView.progress = 1
            }, completion: { (finish: Bool) in

        })
    }
}

First I think the animate can make a variable gradually increase as the alpha property. As a result, I can't get it. So, seek help.

Thx.

Desgard_Duan
  • 659
  • 1
  • 6
  • 12
  • Use a NSTimer and increase the progress value between 0 to 1 incrementally. – Midhun MP May 22 '16 at 15:21
  • Does this answer your question? [How to animate a custom property in iOS](https://stackoverflow.com/questions/41540897/how-to-animate-a-custom-property-in-ios) – Top-Master Apr 29 '21 at 20:21

1 Answers1

0

You are going about this all wrong. You can't animate the changing of a variable. What you should do is use the setProgress:animated: method provided by DACircularProgressView.

func showProgressView() {
    progressView = DACircularProgressView(frame: CGRectMake(UIScreen.mainScreen().bounds.width - 60, 20, 40, 40))
    if let progressView = progressView {
        progressView.progress = 0
        addSubview(progressView)
        progressView.setProgress(1, animated:true)
    }
}

FYI - I'm not a Swift expert so the syntax might not be perfect for the call to setProgress.

rmaddy
  • 314,917
  • 42
  • 532
  • 579