jdg / MBProgressHUD

MBProgressHUD + Customizations
http://www.bukovinski.com/
MIT License
16.01k stars 3.56k forks source link

hideAnimated:afterDelay invoke after handleHideTimer but before done method #503

Closed blackchena closed 7 years ago

blackchena commented 7 years ago

done method will invalid current timer ,cause the showing(hide after delay) hud don't hide

matej commented 7 years ago

I'm sorry, but I don't understand what are you trying to say. Can you be more specific or write a failing test case?

blackchena commented 7 years ago

I will call the follow method when a network request failed: [aWindowGlobalHud showAnimated:YES]; [aWindowGlobalHud hideAnimated:YES afterDelay:delay]; The above method call internally: [self hideUsingAnimation:self.useAnimation] --[self animateIn:NO withType:self.animationType completion:^(BOOL finished) { [self done]; }]; If at the same time another follow method is called [aWindowGlobalHud showAnimated:YES]; [aWindowGlobalHud hideAnimated:YES afterDelay:delay]; aWindowGlobalHud may not be hidden,because a new hideDelayTimer(created at [aWindowGlobalHud hideAnimated:YES afterDelay:delay] method) be invalid at the [self done] method

blackchena commented 7 years ago

you can add the follow code :

     - (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    UIViewController *rootViewController = UIApplication.sharedApplication.keyWindow.rootViewController;
    UIView *rootView = rootViewController.view;
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:rootView animated:NO];
    [hud showAnimated:YES];
    [hud hideAnimated:YES afterDelay:0.3];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.3 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
        [hud showAnimated:YES];
        [hud hideAnimated:YES afterDelay:0.3];
    });

}

in the HudDemo Project's MBHudDemoViewController.m, hud won't be hidden

matej commented 7 years ago

You have an issue in your code, that would prevent this from working correctly. You should not ue the showHUDAddedTo:animated: helper, if you plan on reusing the HUD.

But if you modify the code like this, your report is valid:

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    UIViewController *rootViewController = UIApplication.sharedApplication.keyWindow.rootViewController;
    UIView *rootView = rootViewController.view;
    MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:rootView];
    [rootView addSubview:hud];
    [hud showAnimated:YES];
    [hud hideAnimated:YES afterDelay:0.3];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.3 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
        [hud showAnimated:YES];
        [hud hideAnimated:YES afterDelay:0.3];
    });
}

There is a race here. I think this should fix it: https://github.com/matej/MBProgressHUD/pull/90.

matej commented 7 years ago

Resolved in https://github.com/matej/MBProgressHUD/pull/90.

blackchena commented 7 years ago

Thank you very much!