裁剪中的 UIImagePickerController 状态栏问题 [英] UIImagePickerController status bar issue in crop

查看:33
本文介绍了裁剪中的 UIImagePickerController 状态栏问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 UIViewControllerBasedStatusBarAppearancepreferredStatusBarStyle 来管理状态栏的颜色和外观.

I'm using UIViewControllerBasedStatusBarAppearance and preferredStatusBarStyle to manage the status bar color and appearance.

我的应用程序允许用户从他的相机胶卷中选择一张照片,并使用 UIImagePickerController 的本机裁剪选项将其裁剪为正方形.

My app lets the user choose a photo from his camera roll and crop it to square using the native crop option of UIImagePickerController.

所以我推送一个 UIImagePickerController 并启用编辑以获取裁剪屏幕.
问题是,我希望相册和照片视图的状态栏为白色,而裁剪视图我想隐藏状态栏.

So I push a UIImagePickerController and enable editing to get the crop screen.
The problem is, I want that for the albums and photos view, the status bar will be white, and for the crop view I want to hide the status bar.

如何使用 preferredStatusBarStyle 做到这一点?

how can I do that with preferredStatusBarStyle ?

直到现在我为 UIImagePickerController 创建了一个类别并实现了:

until now I made a category for UIImagePickerController and implemented:

- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}  

这确实将照片中的状态栏设置为白色,但是在裁剪视图时,状态栏变为黑色,这对我来说可能有好处,因为我想隐藏它并且背景是黑色的所以你不能看到它,但是电池指示灯是绿色的!所以你只能在状态栏中看到电池指示灯!

this indeed set the status bar to white color in photos, but when going to crop view, the status bar becomes black, that could be good for me because I want to hide it and the background is black so you can't see it, BUT the battery indicator is green! so you only see the battery indicator in the status bar!

我该如何解决?如何仅在裁剪视图中隐藏状态栏?

how can I solve that? how can I hide the status bar only in the crop view?

推荐答案

Andy 帖子的后续,是的,子类化 UIImagePickerController 曾经是被禁止的,但现在是允许的.但是,尝试覆盖 prefersStatusBarHiddenpreferredStatusBarStyle 时会出现一些意外问题.

Sort of a followup to Andy's post, yes subclassing UIImagePickerController used to be forbidden but is allowed now. There's some unexpected issues trying to override prefersStatusBarHidden and preferredStatusBarStyle though.

注意 UIImagePickerControllerUINavigationController 的子类,因此它本身是子视图控制器的容器.容器视图控制器如何通过覆盖 childViewControllerForStatusBarHiddenchildViewControllerForStatusBarStyle 来控制其子级的状态栏可见性和样式.一般来说,UINavigationController 不会实现这些,通常会覆盖它们以返回当前可见的视图控制器.

Note how UIImagePickerController is a subclass of UINavigationController and so itself is a container for child view controllers. How a container view controller controls status bar visibility and style to its children is by overriding childViewControllerForStatusBarHidden and childViewControllerForStatusBarStyle. In general UINavigationController doesn't implement those and usually one overrides them to return the currently visible view controller.

在这种情况下,您不控制子视图控制器,您的选择器子类可以覆盖这些方法以返回 nil,然后您的 prefer<实现/code> 方法应该接管.理论上,你只需要让它们在正确的时间返回你需要的东西,但正如我的经验所证明的那样,UIImagePickerController 和状态栏样式有些可疑.

In a case like this though, where you don't control the child view controllers, your picker subclass can override these methods to return nil, and then your implementations of the prefer methods should take over. In theory, you then just have to make them return what you need at the right time, but as evidenced by my experience, there's something fishy going on with UIImagePickerController and the status bar style.

对于我自己的 UIImagePickerController 子类,鉴于其自定义 UI,我不关心子视图控制器,但我已经尝试从 childViewController 返回 nil.. 并覆盖 prefer 方法.我发现控制可见性可以正常工作,但是选择器中的某些内容可以抵消我的子类从 preferredStatusBarStyle 返回 LightContent.请参阅我自己的问题.

For my own UIImagePickerController subclass, I don't care about child view controllers given its custom UI, but I've experimented with returning nil from childViewController.. and overriding the prefer methods. I've found that controlling the visibility to work fine, but something in the picker to counteract my subclass returning LightContent from preferredStatusBarStyle. See my own question.

这篇关于裁剪中的 UIImagePickerController 状态栏问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆