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

时间:2010-08-22 16:49:46

标签: iphone uiimagepickercontroller statusbar

一旦我将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];

6 个答案:

答案 0 :(得分:29)

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

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

答案 1 :(得分:15)

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

使用

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

而不是

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

动画参数的有效值为UIStatusBarAnimationNoneUIStatusBarAnimationFadeUIStatusBarAnimationSlide。详情见documentation

答案 2 :(得分:6)

在阅读完并没有找到任何答案后,我设法通过以下方式使其工作:

•为UIImagePickerController设置委托 •在该代理中,隐藏代理的navigationController:didShowViewController:animated:功能中的状态栏。

E.G:

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

答案 3 :(得分:1)

将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。

答案 4 :(得分:0)

好吧,我知道你不应该这样做,但如果你是UIImagePickerController的子类,你可以把它放在你的自定义类中:

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

答案 5 :(得分:0)

所有解决方案都不适用于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所需的相同基本照片捕获。它也可以更好地工作 - 与UIImagePickerController相比,AVCaptureSession的启动速度更快,与UIImagePicker相机预览相比,AVCaptureVideoPreviewLayer在现代设备上具有更好的帧速率。