mutualmobile / MMProgressHUD

An easy-to-use HUD interface with personality.
MIT License
705 stars 131 forks source link

statubar change to black in iOS7 #12

Closed fdddf closed 10 years ago

fdddf commented 10 years ago

My default status bar state is UIStatusBarStyleLightContent. When the MMProgressHUD shows, uistatusbar change to black, and will back to normal light content after dismiss.

larsacus commented 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.

fdddf commented 10 years ago

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.

larsacus commented 10 years ago

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

fdddf commented 10 years ago

For friendly, think about to use the current active view controller's preferred status bar style. That's may better.

larsacus commented 10 years ago

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.

larsacus commented 10 years ago

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.

fdddf commented 10 years ago

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;
}
larsacus commented 10 years ago

Check out my last commit to master. It was essentially a 2-line fix.

fdddf commented 10 years ago

Awesome, I've tested, it works fine. BTW, can you fix warnings in IOS7, thanks.

larsacus commented 10 years ago

The unused variable warning? Yes, I've fixed it. The variable wasn't unused, so I'm not sure why clang thinks it is.

fdddf commented 10 years ago

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

larsacus commented 10 years ago

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.