iOS SDK - 使用 UIImagePickerController 时如何恢复状态栏?
一旦我将 UIImagePickerController 子视图添加到我的视图中,状态栏就会消失并且我无法将其恢复。有什么办法可以让状态栏保持可见吗?
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self.view addSubview:imagePicker.view];
[imagePicker viewWillAppear:YES];
[imagePicker viewDidAppear:YES];
[[UIApplication sharedApplication] setStatusBarHidden:NO animated:NO];
As soon as I add a UIImagePickerController sub view to my view the status bar disappears and I can't get it back. Is there any way to keep the status bar visible?
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self.view addSubview:imagePicker.view];
[imagePicker viewWillAppear:YES];
[imagePicker viewDidAppear:YES];
[[UIApplication sharedApplication] setStatusBarHidden:NO animated:NO];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我也必须在相机应用程序中做同样的事情。显然,除了将状态栏设置为不隐藏之外,还必须在相机视图使其消失后重置其样式。试试这个:
I had to do the same thing in a camera app as well. Apparently, in addition to setting the status bar to not be hidden, you also have to reset its style after the camera view makes it disappear. Try this:
同时,接受的答案的解决方案已被弃用。
使用
动画参数的
有效值为
UIStatusBarAnimationNone
、UIStatusBarAnimationFade
、UIStatusBarAnimationSlide
。详细信息可在文档。The accepted answer's solution got deprecated meanwhile.
Use
instead of
Valid values for the animation parameter are
UIStatusBarAnimationNone
,UIStatusBarAnimationFade
,UIStatusBarAnimationSlide
. Details are found in the documentation.阅读本文并发现所有答案均无效后,我设法通过执行以下操作使其正常工作:
• 为 UIImagePickerController 设置委托
• 在该委托中,隐藏委托的
navigationController:didShowViewController:animated:
函数中的状态栏。例如:
After reading this and finding none of the answers worked, I managed to get it working by doing the following:
• Setting a delegate for the UIImagePickerController
• In that delegate, hide the status bar in the delegate's
navigationController:didShowViewController:animated:
function.E.G:
将 UIImagePicker 添加到根视图(即导航控制器或 TabbarController)
之后,您可以使用它
来关闭 ImagePicker。
Add your UIImagePicker to the root view (i.e. a Navigation Controller or TabbarController)
After that you can use
to close your ImagePicker.
好吧,我知道你不应该这样做,但是如果你继承 UIImagePickerController,你可以将其放入你的自定义类中:
well, I know you are not supposed to do this, but if you subclass UIImagePickerController, you can put that in your custom class:
所有解决方案均不适用于 iOS 5.1.1
Tim 的解决方案适用于 iOS 4.2.1
我能够在 iOS 5.1.1 上解决这个问题的唯一方法就是这样,
这是非常hacky和错误的。
我花了半天时间寻找解决方案,然后决定只使用 AVFoundation 方法,我花了一个小时才使用 AVCaptureSession 和 AVCaptureStillImageOutput 实现我需要的相同基本照片捕获。而且它的效果也更好 - AVCaptureSession 的启动速度比 UIImagePickerController 更快,并且与 UIImagePicker 相机预览相比,AVCaptureVideoPreviewLayer 在现代设备上具有更好的帧速率。
None of the solutions worked on iOS 5.1.1
Tim's solution worked on iOS 4.2.1
The only way I was able to fix the problem on iOS 5.1.1 was like that
which is very hacky and wrong.
I spent half a day looking for a solution and then decided to just use AVFoundation approach and it took me an hour to implement the same basic photo capture that I needed using AVCaptureSession and AVCaptureStillImageOutput. And it works better too - AVCaptureSession starts faster than UIImagePickerController and AVCaptureVideoPreviewLayer has a much better frame rate on modern devices compared to UIImagePicker camera preview.