Skip to content

Commit

Permalink
Added delayed display.
Browse files Browse the repository at this point in the history
  • Loading branch information
Austin Ziegler committed Nov 8, 2009
1 parent fee25a5 commit ce752d9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Demo/Classes/HudDemoViewController.m
Expand Up @@ -156,7 +156,7 @@ - (IBAction)showWithLabelMixed:(id)sender
- (void)myTask
{
// Do something usefull in here instead of sleeping ...
sleep(1);
sleep(1 + (delay / 1000));
// Labels can be changed during the execution
//HUD.detailsLabelText = @"Something";
//sleep(3);
Expand Down
2 changes: 2 additions & 0 deletions MBProgressHUD.h
Expand Up @@ -90,6 +90,8 @@ typedef enum
float opacity;
UIFont* labelFont;
UIFont* detailsLabelFont;

BOOL isFinished;
}

/** A convenience constructor that initializes the HUD with the window's bounds. Calls the designated constructor with
Expand Down
26 changes: 24 additions & 2 deletions MBProgressHUD.m
Expand Up @@ -172,6 +172,8 @@ - (id)initWithFrame:(CGRect)frame

// Add details label
detailsLabel = [[UILabel alloc] initWithFrame:self.bounds];

isFinished = NO;
}
return self;
}
Expand Down Expand Up @@ -333,13 +335,31 @@ - (void)showWhileExecuting:(SEL)method onTarget:(id)target withObject:(id)object
objectForExecution = [object retain];
useAnimation = animated;

// Show HUD view
[self showUsingAnimation:useAnimation];
if (delay)
{
[NSThread detachNewThreadSelector:@selector(delayedShow) toTarget:self withObject:nil];
}
else
{
// Show HUD view
[self showUsingAnimation:useAnimation];
}

// Launch execution in new thread
[NSThread detachNewThreadSelector:@selector(launchExecution) toTarget:self withObject:nil];
}

- (void)delayedShow
{
NSUInteger usecDelay = delay * 1000;
usleep(usecDelay);

if (!isFinished)
{
[self showUsingAnimation:useAnimation];
}
}

- (void)launchExecution
{
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
Expand All @@ -361,6 +381,8 @@ - (void)animationFinished:(NSString*)animationID finished:(BOOL)finished context

- (void)done
{
isFinished = YES;

// If delegate was set make the callback
self.alpha = 0.0;
if (delegate != nil)
Expand Down

0 comments on commit ce752d9

Please sign in to comment.