Giter Club home page Giter Club logo

Comments (4)

jamesalester avatar jamesalester commented on May 22, 2024 2

That's awesome! Cheers mate, I really appreciate it. It's working perfectly now!

from uicircularprogressring.

luispadron avatar luispadron commented on May 22, 2024

Sure, so using your code you could try something like

func animateCircularProgressView(delayTime: Int) {

    // This would be a class property in the view controller
    self.isProgressRingAnimating = true

    progressRing.setProgress(value: 100, animationDuration: TimeInterval(delayTime*2)) {
        // Remove the resetting of the progress ring from here, handle that in the button code like you wanted
        // Done animating so set it to false
        self.isProgressRingAnimating = false
    }
}

Then you can do

@IBAction func btnTapped(_ sender: AnyObject) {
   // Check to see if ring is animating
    if isProgressRingAnimating {
       // You said you wanted to check to see if it was animating, and if the user pressed the button, then reset the ring
      // So to reset, just send in an animationDuration of 0
     self.progressRing.setProgress(value: 0, animationDuration: 0, completion: nil) // assuming your min value is 0
    } else {
         // do button stuff
    }
}

Maybe I should add a property into the UICircularProgressRing API which will let you know if it's animating or not, but for right now this should work.

Let me know if this is what you were after.

Edit:

Looking at this more maybe what you want is more along the lines of just restarting the animation, instead of stopping/resetting it.

In that case try this:

@IBAction func btnTapped(_ sender: AnyObject) {
    if timerIsOn {
        //playErrorSound()
        // Reset the progress ring before starting it again
        timerIsOn = false
        self.progressRing.setProgress(value: 0, animationDuration: 0, completion: nil) // assuming your min value is 0
        animateCircularProgressView(delayTime: time)
    } else {
         // do button stuff
    }
}

from uicircularprogressring.

jamesalester avatar jamesalester commented on May 22, 2024

Hi, thanks for the reply. Sorry, I didn't mean reset as in make it 0, I meant reset the animation as in restart the animation again.

Removing the setProgress to 0 in the completion seems to stop it from disappearing which is good. I think the problem I am having now is that the timerIsOn/isProgressAnimating check is setting itself to false so after the 2nd time the button is clicked even when it is still animating it is carrying out the "// do button stuff" bit instead of reseting the animation again. I think the original animation, even though you can't see it because the progress has been set back to 0, is still going and then sets the isProgressAnimating to false. When I stick a print function in there like:

func animateCircularProgressView(delayTime: Int) {

    // This would be a class property in the view controller
    self.isProgressRingAnimating = true

    progressRing.setProgress(value: 100, animationDuration: TimeInterval(delayTime*2)) {
        // Remove the resetting of the progress ring from here, handle that in the button code like you wanted
        // Done animating so set it to false
        self.isProgressRingAnimating = false
       print("Done animating")
    }
}

When the button gets pressed again it shows "Done animating" twice. Is there a way to cancel the original animation? Sorry if this is confusing.

Edit:
Just saw your edit. That's closer to what I mean but I'm still getting the problem where timerIsOn is being set to false so clicking again doesn't restart it again

from uicircularprogressring.

luispadron avatar luispadron commented on May 22, 2024

Okay, so there was no clean way of doing this without me updating the project.

Version 1.1.4

Run pod update if using cocoapods.

Now every UICircularProgressRing has an isAnimating property.

This should now allow the restarting animation behavior you want:

func animateCircularProgressView(delayTime: Int) {
    progressRing.setProgress(value: 100, animationDuration: TimeInterval(delayTime*2)) {
        // Completion no longer needed, remove if you want
    }
}

@IBAction func btnTapped(_ sender: AnyObject) {
    if self.progressRing.isAnimating {
        //playErrorSound()
        // Reset the progress ring before starting it again
        self.progressRing.setProgress(value: 0, animationDuration: 0, completion: nil) // assuming your min value is 0
        animateCircularProgressView(delayTime: time)
    } else {
         // do button stuff
    }
}

from uicircularprogressring.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.