Closed fdddf closed 10 years ago
This looks like it has to do with the root view controller that MMProgressHUD's window is using taking control of the status bar style. It looks like a new property will have to be added to MMProgressHUD/MMProgressHUDWindow to support setting the status bar style. Alternatively, it could somehow be auto-detected from the current window's status bar style, though this might not be 100% reliable.
I think we could read status bar state from the project plist and set on MMProgressHUDWindow, though I'm not sure if that is possible.
If the developer has their status bar state delegated to the current view controller, then the plist method will not work reliably -- it still may be incorrect for the current state before you display MMProgressHUD
For friendly, think about to use the current active view controller's preferred status bar style. That's may better.
there is also the case that the developer is not using UIViewController-based status bar state changes. You can also bypass the view controller state by using the -[UIApplication statusBarStyle]
method when not using the VC-based status bar system.
Ok so it actually looks like the solution is pretty simple. Even when using VC-based status bar styling, the -[UIApplication statusBarStyle]
and -[UIApplication isStatusBarHidden]
methods still return the current status bar style. This prevents us from having to go and find the current window's root view controller's top view controller and get the style from that.
Thanks, you are right. I fixed it. Add functions
+ (UIViewController*)topMostController;
in MMProgressHUDWindow.h and MMProgressHUDWindow.m
///http://stackoverflow.com/a/12684721/572431
+ (UIViewController*)topMostController
{
UIViewController *topController = [UIApplication sharedApplication].keyWindow.rootViewController;
while (topController.presentedViewController) {
topController = topController.presentedViewController;
}
return topController;
}
MMProgressHUDViewController.m
- (UIStatusBarStyle)preferredStatusBarStyle
{
return [MMProgressHUDWindow topMostController].preferredStatusBarStyle;
}
Check out my last commit to master. It was essentially a 2-line fix.
Awesome, I've tested, it works fine. BTW, can you fix warnings in IOS7, thanks.
The unused variable warning? Yes, I've fixed it. The variable wasn't unused, so I'm not sure why clang thinks it is.
MMHud.m:100:37: 'sizeWithFont:' is deprecated: first deprecated in iOS 7.0 - Use -sizeWithAttributes:
MMHud.m:105:32: 'sizeWithFont:constrainedToSize:' is deprecated: first deprecated in iOS 7.0 - Use -boundingRectWithSize:options:attributes:context:
MMProgressHUDViewController.m:31:11: 'setWantsFullScreenLayout:' is deprecated: first deprecated in iOS 7.0
Ah, you have an iOS 7-only target. I still have the demo targeting iOS 6.
Open up a new issue for those and I will close this one.
My default status bar state is UIStatusBarStyleLightContent. When the MMProgressHUD shows, uistatusbar change to black, and will back to normal light content after dismiss.