UIImagePickerController status bar output in crop
I use UIViewControllerBasedStatusBarAppearance
both preferredStatusBarStyle
to control the color and appearance of the status bar.
My app allows the user to select a photo from their camera roll and crop it to a square using the crop option UIImagePickerController
.
So, I click UIImagePickerController
and allow editing to get the crop screen.
The problem is, I want the status bar to be white for Albums and Photos view, and I want to hide the status bar for crop view.
how can i do this with preferredStatusBarStyle
?
so far I've created a category for UIImagePickerController
and implemented:
- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}
this did set the status bar to white in the photos, but when going into crop mode, the status bar turns black, this might be useful to me because I want to hide it and the background is black so you can't see it BUT indicator battery green! so you see the battery indicator in the status bar!
how can i solve this? how can I hide the status bar in trim view only?
You will need to do a bit of work here, but I can give you an edge.
I suggest subclassing UIImagePickerController
and returning your state settings according to the displayed child controller.
UIViewController has two methods that allow you to control the visibility and appearance of the status bar:
- (BOOL)prefersStatusBarHidden;
- (UIStatusBarStyle)preferredStatusBarStyle
Just override them, no call required super
.
You have access to the breakpoint stack in the subclass, so you can choose your preferred style and visibility for the status bar according to the number of controllers on the stack.
I have a feeling that UIKit will ping preferredStatusBarStyle
and prefersStatusBarHidden
every time a new child controller is pushed onto the stack.
If not, you can force UIKit to update the status bar by calling:
[self setNeedsStatusBarAppearanceUpdate]
Since it UIImagePickerController
is a subclass UINavigationController
, you can assign your own delegate to it, watch as the new controller is pushed onto the stack, and the suggested code above is called.
Tracking in Andy , yes, subclasses UIImagePickerController
were forbidden, but are now allowed. There are some unexpected issues trying to override prefersStatusBarHidden
and preferredStatusBarStyle
though.
Note that it UIImagePickerController
is a subclass UINavigationController
and therefore is itself a container for the child view controllers. How a container controller controls the visibility and style of the status bar for its children by overriding childViewControllerForStatusBarHidden
and childViewControllerForStatusBarStyle
. Usually UINavigationController
does not implement them and usually one overrides them to return the currently visible view controller.
In such a case, though, if you don't have control over the child view controllers, your pick subclass can override these methods to return nil
, and then your method implementations prefer
should take over. In theory, you just need to get them to return what you need at the right time, but in my experience there is something fishy about working with UIImagePickerController
and styling the status bar.
For my own subclass, UIImagePickerController
I don't care about child view controllers given my UI, but I did experiment with returning nil
from childViewController..
and overriding methods prefer
. I found that the visibility control works fine, but there is something in the collector to counteract my subclass returning LightContent
from preferredStatusBarStyle
. See my own question .