dbettermann / DBAlertController

A UIAlertController subclass that's independent of the view controller it's presented from. i.e. Adding UIAlertView's show() to UIAlertController.
MIT License
58 stars 19 forks source link

UIStatusBar problems #5

Closed efimovdk closed 8 years ago

efimovdk commented 9 years ago

Thank you for this convenient class. Everything works fine except one thing. What if I want to keep UIStatusBar preferences(light or dark, hidden or not) of current view controller when I show alert above it? Suppose I have a UIViewControllerwith UIStatusBarStyleLightContent. When I show alert view, it becomes black. I have different scenarios in my app, so it is really really bad to do all that stuff manually by saying: if AViewController is below then light bar, if BViewController than the bar is hidden, if C and so on. Any advices to this?

dbettermann commented 9 years ago

You're welcome! I believe it has to do with windowLevel of the private window. I'll spend some time on it later today.

dbettermann commented 9 years ago

Sorry for the delay. I put in a fix and pushed out a new version of the pod. Feel free to pull down the repo or use version 0.2.0.

I'll close the issue if I don't hear back in a few days. Thanks again.

esetnik commented 8 years ago

Thanks for the useful pod! I'm having a similar issue that is caused by the behavior introduced in 0.2.0.

I have a view controller transition that involves view based status bar presentation for two view controllers (let's call them A and B): A (prefersStatusBarHidden -> true) -> B (prefersStatusBarHidden -> false). Without showing an alert the status bar behavior is correct in that it is hidden in A and visible in B, but when I show a DBAlertController during the transition from A -> B then B's view frame is negative y offset by the height of the status bar. This causes the status bar to appear on top of the navigation bar while the alert is visible. When the alert is dismissed, B keeps it's incorrect offset and B's status bar is hidden.

My understanding of this problem is that

 private override func prefersStatusBarHidden() -> Bool {
        return UIApplication.sharedApplication().statusBarHidden
    }

is returning the prefersStatusBarHidden() for A when it should be consulting B causing B to be incorrectly hidden.

esetnik commented 8 years ago

simulator screen shot dec 23 2015 1 39 15 pm simulator screen shot dec 23 2015 1 39 27 pm

dbettermann commented 8 years ago

Hey thanks for the information!

If I'm understanding you correctly, you're using view controller-based status bar appearance. DBAlertController does not currently have support for this feature. We would need a reference to the visible view controller to get the current status bar properties, but DBAlertController essentially just adds a new UIWindow to the top of the view hierarchy (without looking at the visible view controller).

I have a fix in mind, but I'm going to consider all the options before applying the fix. Suggestions are welcome!

esetnik commented 8 years ago

Maybe I misunderstood. I see this which leads me to believe the intention is to support view controller-based status bar appearance.

// In the case of view controller-based status bar style, make sure we use the same style for our view controller
private class DBClearViewController: UIViewController {

    private override func preferredStatusBarStyle() -> UIStatusBarStyle {
        return UIApplication.sharedApplication().statusBarStyle
    }

    private override func prefersStatusBarHidden() -> Bool {
        return UIApplication.sharedApplication().statusBarHidden
    }

}
esetnik commented 8 years ago

Actually I just created a sample project and i'm unable to reproduce the issue. This might be an incompatibility with RESideMenu. I'm looking into it now.

dbettermann commented 8 years ago

Just realized that what I said may be wrong. UIApplication.sharedApplication().statusBar... may actually be the right value depending on when it's called (i.e. calling it right before the alert is presented may get the correct value).

Let me know what you figure out with RESideMenu.

dbettermann commented 8 years ago

Correction: Just realized what I said is completely wrong. Sorry, I'm going down a rabbit hole for a different project, so my mind is a little scrambled at the moment.