问题
I'm subclassing UIImagePickerController
in attempt to override its default status bar behavior and having mixed results. My app uses view controller-based status bar appearance.
Without subclassing, I'm finding that it changes the status bar style to Default
(dark) when the picker is dismissed, and nothing I've tried yet in my initial view controller is fixing it. Also, when the picker hides the status bar while being presented, sliding it upwards, the initial view controller's navigation bar slides up with it from height 64 to 44.
So I want my UIImagePickerController
subclass to keep the status bar style as LightContent
and, in an attempt to work-around the sliding navigation bar, keep the status bar showing while presenting the picker, then hide it on viewDidAppear:
.
The first interesting thing is that preferredStatusBarStyle
and prefersStatusBarHidden
in my picker subclass weren't called at all until I also overrode childViewControllerForStatusBarStyle
and childViewControllerForStatusBarHidden
to return nil. This seems to indicate that normally, a UIImagePickerController
is overriding those, probably to return an internal child view controller. Looking at the view hierarchy in viewDidAppear:
, there's certainly a child PLImagePickerCameraView
and its likely there's a controller to go with it. Sadly we cannot override this controller.
Overriding those childViewControllerFor...
methods, preferredStatusBarStyle
and prefersStatusBarHidden
do get called in-between viewWillAppear:
and viewDidAppear:
, and can indeed keep the status bar visible and LightContent
. The second interesting thing though, is that before the presentViewController
animation the status bar briefly blinks dark. No amount of extra calls to setNeedsStatusBarAppearanceUpdate
in viewWillAppear:
or other places such as viewDidLoad:
seem to prevent that.
The third interesting thing is that the bar style is still getting set to dark during dismissal, and no extra calls to setNeedsStatusBarAppearanceUpdate
in the picker's viewWillDisappear:
or viewDidDisappear:
seem to prevent that.
tl;dr -- I've found that overriding UIImagePickerController
to hide & show the status bar on demand to work pretty well, but setting the bar style is problematic. Something in the picker class or UINavigationController
itself is automatically preferring the Default
bar style, and when its switched to that on dismissal, it seems difficult to switch it back.
I've seen the Question UIImagePickerController breaks status bar appearance, and nothing I've seen there has helped yet, and iOS8.1 doesn't fix it. I was sure that setting the picker's navigationBar.barStyle
to black would do it, but no dice. Any ideas anybody?
(Also, any tips on preventing a UINavigationController
's navigation bar from sliding up to 44 height when the status bar is hidden would be useful thx)
来源:https://stackoverflow.com/questions/27629714/uiimagepickercontroller-vs-status-bar-ios8