22

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];
dan
  • 1,067
  • 3
  • 11
  • 17

6 Answers6

29

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];
Brad The App Guy
  • 16,255
  • 2
  • 41
  • 60
  • Brad, this isn't working for me, I'm doing it in loadView, viewDidLoad and viewDidAppear all to no avail. – Jesse Pepper Nov 11 '10 at 07:13
  • Brad, this worked well for me. In fact, I had to use setStatusBarHidden when switching between the camera and the photo library sourceType. – cpungaliya May 06 '11 at 22:33
  • How do I get a handle on this status bar so that I can display some text on it while my application is in the background? – Namratha Aug 11 '11 at 08:42
  • 2
    -setStatusBarHidden:animated is deprecated, use -setStatusBarHidden:withAnimation: instead, check alex's answer below. – lekksi Jul 18 '14 at 16:23
15

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.

alex
  • 2,464
  • 23
  • 32
6

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];
}
Tim
  • 597
  • 1
  • 5
  • 15
1

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.

Henrik P. Hessel
  • 36,243
  • 17
  • 80
  • 100
  • Hi Henrik, thanks for your reply. I want the status bar visible all the time. Is that possible? – dan Aug 22 '10 at 16:57
0

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.

borisgolovnev
  • 1,780
  • 16
  • 20
0

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];
}
rptmat57
  • 3,643
  • 1
  • 27
  • 38