Search code examples
iostvosuiprogressview

Knowing when a UIProgressView stops animating


UIProgressView has this setProgress:animated: API.

Is there a way to know exactly when the animation stops?

I mean something like this?

[myProgress setProgress:0.8f animated:YES onCompletion...]

I would like to start fading the progress out, as soon as its animation ends.


Solution

  • From: https://stackoverflow.com/a/16368679/74815

    When you are not the author of the animation, you can get a callback when the animation ends by using a transaction completion block:

    [CATransaction setCompletionBlock:^{
         // doSomethingElse
    }];
    // doSomething
    

    From the Apple documentation:

    Discussion

    The completion block object that is guaranteed to be called (on the main thread) as soon as all animations subsequently added by this transaction group have completed (or have been removed.) If no animations are added before the current transaction group is committed (or the completion block is set to a different value,) the block will be invoked immediately.