iOS SDK - 使用 UIImagePickerController 时如何恢复状态栏?

发布于 2024-09-15 16:00:46 字数 436 浏览 8 评论 0原文

一旦我将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

迷荒 2024-09-22 16:00:46

我也必须在相机应用程序中做同样的事情。显然,除了将状态栏设置为不隐藏之外,还必须在相机视图使其消失后重置其样式。试试这个:

[[UIApplication sharedApplication] setStatusBarHidden:NO animated:NO];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent animated:YES];

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:

[[UIApplication sharedApplication] setStatusBarHidden:NO animated:NO];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent animated:YES];
猫腻 2024-09-22 16:00:46

同时,接受的答案的解决方案已被弃用。

使用

[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];

动画参数的

[[UIApplication sharedApplication] setStatusBarHidden:NO animated:NO];

有效值为 UIStatusBarAnimationNoneUIStatusBarAnimationFadeUIStatusBarAnimationSlide。详细信息可在文档

The accepted answer's solution got deprecated meanwhile.

Use

[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];

instead of

[[UIApplication sharedApplication] setStatusBarHidden:NO animated:NO];

Valid values for the animation parameter are UIStatusBarAnimationNone, UIStatusBarAnimationFade, UIStatusBarAnimationSlide. Details are found in the documentation.

泛泛之交 2024-09-22 16:00:46

阅读本文并发现所有答案均无效后,我设法通过执行以下操作使其正常工作:

• 为 UIImagePickerController 设置委托
• 在该委托中,隐藏委托的navigationController:didShowViewController:animated: 函数中的状态栏。

例如:

-(void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    [[UIApplication sharedApplication] setStatusBarHidden:NO];
}

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:

-(void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    [[UIApplication sharedApplication] setStatusBarHidden:NO];
}
束缚m 2024-09-22 16:00:46

将 UIImagePicker 添加到根视图(即导航控制器或 TabbarController)

[self.tabBarController presentModalViewController:imagePickerController animated:YES];

之后,您可以使用它

- (void)imagePickerController:(UIImagePickerController *)picker 
            didFinishPickingImage:(UIImage *)image
                      editingInfo:(NSDictionary *)editingInfo
{
      // do your stuff
     [picker dismissModalViewControllerAnimated:YES];
}

来关闭 ImagePicker。

Add your UIImagePicker to the root view (i.e. a Navigation Controller or TabbarController)

[self.tabBarController presentModalViewController:imagePickerController animated:YES];

After that you can use

- (void)imagePickerController:(UIImagePickerController *)picker 
            didFinishPickingImage:(UIImage *)image
                      editingInfo:(NSDictionary *)editingInfo
{
      // do your stuff
     [picker dismissModalViewControllerAnimated:YES];
}

to close your ImagePicker.

时光磨忆 2024-09-22 16:00:46

好吧,我知道你不应该这样做,但是如果你继承 UIImagePickerController,你可以将其放入你的自定义类中:

-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    [[UIApplication sharedApplication] setStatusBarHidden:NO];
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent animated:YES];
}

well, I know you are not supposed to do this, but if you subclass UIImagePickerController, you can put that in your custom class:

-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    [[UIApplication sharedApplication] setStatusBarHidden:NO];
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent animated:YES];
}
Oo萌小芽oO 2024-09-22 16:00:46

所有解决方案均不适用于 iOS 5.1.1
Tim 的解决方案适用于 iOS 4.2.1
我能够在 iOS 5.1.1 上解决这个问题的唯一方法就是这样,

-(void)viewDidAppear:(BOOL)animated
{
    double delayInSeconds = 0.01;
    dispatch_time_t popTime = 
            dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
    [[UIApplicationsharedApplication] setStatusBarHidden:NO];
});

这是非常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

-(void)viewDidAppear:(BOOL)animated
{
    double delayInSeconds = 0.01;
    dispatch_time_t popTime = 
            dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
    [[UIApplicationsharedApplication] setStatusBarHidden:NO];
});

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文