Skip to content

Commit

Permalink
Better interaction between hide delay and minimum show time using dis…
Browse files Browse the repository at this point in the history
…patch_after.

Signed-off-by: Zachary Waldowski <zwaldowski@gmail.com>
  • Loading branch information
zwaldowski committed Jan 30, 2012
1 parent b30b849 commit d79de27
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions MBProgressHUD.m
Expand Up @@ -390,22 +390,26 @@ - (void)hide:(BOOL)animated {
}

- (void)hide:(BOOL)animated afterDelay:(NSTimeInterval)delay {
NSTimeInterval length = animated ? (1./3.) : 0;
NSTimeInterval minimumShowDelay = self.minShowTime - [[NSDate date] timeIntervalSinceDate:showStarted];
if (minimumShowDelay)
delay += minimumShowDelay;

[UIView animateWithDuration:length delay:delay options:UIViewAnimationOptionCurveEaseInOut|UIViewAnimationOptionAllowUserInteraction|UIViewAnimationOptionBeginFromCurrentState animations:^{
if (animationType == MBProgressHUDAnimationZoom)
self.transform = CGAffineTransformConcat(self.transform, CGAffineTransformMakeScale(0.5f, 0.5f));
self.alpha = 0.0f;
} completion:^(BOOL finished) {
if ([delegate respondsToSelector:@selector(HUDWasHidden:)])
[delegate HUDWasHidden:self];
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delay * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^{
NSTimeInterval length = animated ? (1./3.) : 0;
NSTimeInterval minimumShowDelay = 0.0;
if (showStarted)
minimumShowDelay = self.minShowTime - [[NSDate date] timeIntervalSinceDate:showStarted];

if (removeFromSuperViewOnHide)
[self removeFromSuperview];
}];

[UIView animateWithDuration:length delay:minimumShowDelay options:UIViewAnimationOptionCurveEaseInOut|UIViewAnimationOptionAllowUserInteraction|UIViewAnimationOptionBeginFromCurrentState animations:^{
if (animationType == MBProgressHUDAnimationZoom)
self.transform = CGAffineTransformConcat(self.transform, CGAffineTransformMakeScale(0.5f, 0.5f));
self.alpha = 0.0f;
} completion:^(BOOL finished) {
if ([delegate respondsToSelector:@selector(HUDWasHidden:)])
[delegate HUDWasHidden:self];

if (removeFromSuperViewOnHide)
[self removeFromSuperview];
}];
});
}

- (void)showWhileExecuting:(dispatch_block_t)block {
Expand Down

0 comments on commit d79de27

Please sign in to comment.