Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GracePeriod Option #23

Closed
benmarten opened this issue Feb 2, 2015 · 1 comment
Closed

Add GracePeriod Option #23

benmarten opened this issue Feb 2, 2015 · 1 comment

Comments

@benmarten
Copy link

I would like to see an option for setting a grace period. I have subclassed JGProgressHUD for one of my projects. Maybe you want to implement something similar?

import "JGProgressHUD.h"

@interface FSProgressHUD : JGProgressHUD

@Property NSNumber* graceTime;
@Property BOOL taskInProgress;
@Property BOOL showInSuperview;

  • (void)showInView:(UIView*)view;
  • (void)dismiss;

@EnD

import "FSProgressHUD.h"

@interface FSProgressHUD ()

@Property NSTimer* graceTimer;
@Property UIView* view;

@EnD

@implementation FSProgressHUD

/**
Shows the HUD animated. You should preferably show the HUD in a UIViewController's view.
@param view The view to show the HUD in. The frame of the @c view will be used to calculate the position of the HUD.
*/

  • (void)showInView:(UIView*)view
    {
    if (_graceTime && [_graceTime doubleValue] > 0.0) {
    _view = view;
    _taskInProgress = YES;
    _graceTimer = [NSTimer scheduledTimerWithTimeInterval:[_graceTime doubleValue] target:self
    selector:@selector(handleGraceTimer:)
    userInfo:nil
    repeats:NO];
    }
    else {
    [super showInView:view];
    }
    }
  • (void)dismiss
    {
    _taskInProgress = NO;
    [super dismiss];
    }
  • (void)handleGraceTimer:(NSTimer*)theTimer
    {
    if (_taskInProgress) {
    if (_showInSuperview && _view.superview) {
    [super showInView:_view.superview];
    }
    else {
    [super showInView:_view];
    }
    }
    }

@EnD

@JonasGessner
Copy link
Owner

This is unnecessary, a simple dispatch_after call can take care of this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants