mrackwitz / MRProgress

Collection of iOS drop-in components to visualize progress
MIT License
2.55k stars 306 forks source link

Delay the dismiss #21

Closed Isuru-Nanayakkara closed 10 years ago

Isuru-Nanayakkara commented 10 years ago

Hi,

I love this library. This is the second project I'm using it and in this one, I need to delay the dismissing of the view for a couple of seconds. How can I do that? Is there built-in methods for that?

EDIT: I went through your example project and saw that you're using the following method for delaying.

- (void)performBlock:(void(^)())block afterDelay:(NSTimeInterval)delay {
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delay * NSEC_PER_SEC));
    dispatch_after(popTime, dispatch_get_main_queue(), block);
}

As an enhancement I suggest, include this feature within the library itself. :)

Thank you.

mrackwitz commented 10 years ago

Thank you for your feedback. :smile:

If you just want to delay the beginning of the hide animation of the overlay: Apple ships a code snippet for this in the Xcode library. Just type dispatch_after and press enter. You will get the following code:

double delayInSeconds = 2.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
    /* code to be executed on the main queue after delay */
    /* e.g: [MRProgressOverlayView dismissOverlayForView:view animated:YES]; */
});

This is also used in the provided example application as you already mentioned. If you want to use this, I would suggest you take a look at BlocksKit. This library provide a method with a very similar signature and a lot of more helpful stuff. :wink: