Closed blackchena closed 6 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?
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
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
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.
Resolved in https://github.com/matej/MBProgressHUD/pull/90.
Thank you very much!
done method will invalid current timer ,cause the showing(hide after delay) hud don't hide