Status bar issues with orientation change and adaptive interface

Originator:ricciadams
Number:rdar://22814975 Date Originated:
Status:Open Resolved:
Product:UIKit Product Version:
Classification: Reproducible:
 
Summary:
Background information:

Our application's main interface is dark, and hence we use UIStatusBarStyleLightContent for our main view controller's -preferredStatusBarStyle.

Often, we will present child view controller as a modal form sheet.  

As a form sheet, we still want UIStatusBarStyleLightContent (as the dark parent controller is visible).  However, in a horizontal compact environment, the view controller will appear full screen.  Due to the whiteness of the VC, it returns UIStatusBarStyleDefault for -preferredStatusBarStyle to make the status bar black.

Unfortunately, UIKit will often get very confused whether it should be displaying the white status bar or black status bar.  After a lot of diagnosis, we traced this to orientation changes that result in different horizontalSizeClass.

To demonstrate this, run the attached sample project on an iPad Air 2 or iPhone 6 Plus.

1. Start in portrait orientation (on the 6 Plus), or portrait 438w on the iPad.
2. Show the child VC
3. Rotate the device to landscape
4. Dismiss the child VC

The status bar is now black-on-dark-gray until the reverse steps are taken:

5. Show the child VC
6. Rotate back to portrait
7. Dismiss the child VC

Under the hood, step #2 sets the ChildVC as the -_presentedStatusBarViewController of the root view controller.  This would normally be set to nil in step #4; however, due to the orientation change, it is never cleared.

Since _presentedStatusBarViewController is a strong reference, UIKit will keep ChildVC alive even after the main view controller is dismissed/popped.  This burned us multiple times during iOS 9 adoption, as one of our VCs deep in the hierarchy was still alive even when the user returned to our root.

Steps to Reproduce:
(See description)

Expected Results:
1. The status bar always uses the -preferredStatusBarStyle of the view controller underneath it.
2. UIKit doesn't keep a strong reference to my child view controller long after it has been dismissed.

Actual Results:
1. Status bar is the wrong color
2. My view controller is kept alive until something knocks it out of _presentedStatusBarViewController

Version:
iOS 9.0, iOS 9.1 beta 1

Comments

Uploaded sample project to http://iccir.com/public/radar/Radar22814975.zip

By ricciadams at Sept. 23, 2015, 5:46 a.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!