31

I am new to iOS development. I am trying to hide status bar in UIImagePickerController. Whenever I click on "Take photo", status bar appears. It doesn't hide. I want status bar to be hidden only in UIImagePickerController.

Here is my code,

- (IBAction)takePhoto:(UIButton *)sender
{
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.allowsEditing = YES;
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    [self presentViewController:picker animated:YES completion:NULL];
}


- (void)imagePickerController:(UIImagePickerController *)picker     didFinishPickingMediaWithInfo:(NSDictionary *)info
{   
    [self statusBar:YES];
    UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
    self.imageView.image = chosenImage;
    [picker dismissViewControllerAnimated:YES completion:NULL];

}


- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[picker dismissViewControllerAnimated:YES completion:NULL];
}


-(void)statusBar:(BOOL)status
{
    [[UIApplication sharedApplication] setStatusBarHidden:status];
}

How to hide the status bar on UIImagePickerController?

Moin Shirazi
  • 4,372
  • 2
  • 26
  • 38

13 Answers13

47

This worked fine for me:

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

Edit: As of today i just found out that in your info.plist, if you just copy-paste view controller-based status bar appearance there it won't work ... you have to hit enter on a property, and scroll to the last one of them so you will have autocomplete to :view controller-based status bar appearance and an boolean, with no. I tried multiple times but it does not work just copying. Have a nice day.

Mark Loeser
  • 17,657
  • 2
  • 26
  • 34
Alexandru Dranca
  • 830
  • 1
  • 7
  • 21
  • This works perfectly for iOS7,But when pop the photo view, the new photo is on the bottom, the user had to scroll it at the bottom – akin Oct 21 '13 at 08:59
  • With the 'view controller-based status bar appearance' and set to NO, I had still the problem, but this fixed the problem, thanks!!! – xarly Dec 06 '13 at 14:15
  • Doesn't this turn off the status bar for the entire application once the UIImagePickerController is opened? Or not? I want to only turn it off for the camera view. – sffc Jan 05 '14 at 12:38
  • This worked for me too ! However, I noticed a little "glitch" when the UIImagePickerController appeared. I found out that if you use the following method instead, it works without a glitch: [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone]; – Frederic Adda Apr 27 '14 at 20:11
  • Accepted answer did not work for me, but this did +1 – zpasternack Mar 04 '15 at 06:49
  • "setStatusBarHidden" is deprecated on iOS 9. – Nobin Thomas Oct 06 '17 at 02:18
33

The solution I found for applications build around : "View controller-based status bar appearance" set to YES

I did add Category:

//UIImagePickerController+StatusBarHidden.h
#import <UIKit/UIKit.h>

@interface UIImagePickerController (StatusBarHidden)
@end

//UIImagePickerController+StatusBarHidden.h
#import "UIImagePickerController+StatusBarHidden.h"

@implementation UIImagePickerController (StatusBarHidden)

-(BOOL) prefersStatusBarHidden {
    return YES;
}

-(UIViewController *) childViewControllerForStatusBarHidden {
    return nil;
}

@end

The method childViewControllerForStatusBarHidden is used rarely, but image picker do use it, thats why might cause some troubles

You may also implement UIViewController singleton, with method which returns YES or NO, based on its property. Then your View controleller implements childViewControllerForStatusBarHidden returning the above singleton. Changing singleton property automatically change statusbar in app. There also is twin method childViewControllerForStatusBarStyle


However for 2014, iOS8, see this https://stackoverflow.com/a/18960308/294884

Community
  • 1
  • 1
Silvertaurus
  • 384
  • 3
  • 5
  • 1
    The documentation says subclassing isn't supported. So this is a nice option. Worked great (once I set view controller-based status bar appearance back to YES). Thanks. – cloudsurfin Nov 21 '13 at 02:11
  • This works for me and the critical piece is settling childViewControllerForStatusBarHidden to return nil. All the other solutions were all-or-none vis-a-vis status bar display. – farhadf Feb 02 '14 at 21:07
  • You saved my day man! As @farhadf wrote, childViewControllerForStatusBarHidden is the key here. – Błażej Apr 17 '14 at 14:25
  • Brilliant. Works perfectly. – user Jul 03 '14 at 05:19
19

I had an issue where in iOS7 my status bar was not being hidden. I hid it programmatically and it still displayed in iOS7, but when ran in iOS6 the status bar would hide appropriately. You have to go to the plist and add the following:

'view controller-based status bar appearance' and set to NO.

If you want the status bar to re-appear in other view controllers and only be hidden on a particular VC, then you set the status bar to hidden YES when the VC loads. When the VC will disappear you set the status bar hidden back to NO.

- (void)viewDidLoad
{

    [super viewDidLoad];
    [[UIApplication sharedApplication] setStatusBarHidden:YES];

}

and when the controller will disappear you add the following to set the status bar so it is no longer hidden and will display on the next View:

-(void)viewWillDisappear:(BOOL)animated{

     [[UIApplication sharedApplication] setStatusBarHidden:NO];

}

setStatusBarHidden:withAnimation: if you want some smooth animation

ConfusedDeer
  • 3,335
  • 8
  • 44
  • 72
  • 2
    I want to display it all through my app. I just want to hide it in UIImagepickerController. – Shailendra Kumar Gangwar Sep 13 '13 at 04:14
  • 4
    I had set 'view controller-based status bar appearance' to NO in pList and [application setStatusBarHidden:NO]; [application setStatusBarStyle:UIStatusBarStyleDefault]; in appDelegate. This worked for me. Thanks. – Shailendra Kumar Gangwar Sep 16 '13 at 07:51
  • 1
    i am facing same issue.. but setting view controller-based status bar to NO, hide status bar, but if u browse photo it is coming again. – RockandRoll Sep 27 '13 at 07:06
  • this doesn't solve for uiimagepickercontroller only. however, you can you CATransation blocks every time you load the view instead. [CATransaction begin]; [CATransaction setCompletionBlock:^{ [[UIApplication sharedApplication] setStatusBarHidden:YES]; [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault]; }]; imgPicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; [CATransaction commit]; – greenhouse Sep 11 '14 at 06:39
18

subclass UIImagePickerController ... mine is V1ImagePickerController ...

.m file looks like this:

#import "V1ImagePickerController.h"

@interface V1ImagePickerController ()

@end

@implementation V1ImagePickerController

- (void)viewDidLoad
{
    [super viewDidLoad];

    if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1)   // iOS7+ only
    {
        self.edgesForExtendedLayout = UIRectEdgeNone;

        [self prefersStatusBarHidden];
        [self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
    }
}

- (BOOL)prefersStatusBarHidden
{
    return YES;
}

- (UIViewController *)childViewControllerForStatusBarHidden
{
    return nil;
}

@end

the childViewControllerForStatusBarHidden is the key!

user2797041
  • 181
  • 3
  • 2
    -(BOOL)prefersStatusBarHidden { return self.sourceType== UIImagePickerControllerSourceTypeCamera ? YES : NO; } – ngzhongcai Oct 30 '13 at 13:29
  • You don't need the viewDidLoad override, not for the status bar stuff anyway. – jrturton Feb 25 '14 at 09:22
  • Also see Masmor's answer here: http://stackoverflow.com/questions/18856627/ios-7-status-bar-overlaps-camera-controls-on-uiimagepickercontroller It's the only way to do it. – Fattie Feb 28 '14 at 15:11
7

If you want to disable the status bar from plist, try this:

  1. Status bar is initially hidden : YES
  2. View controller-based status bar appearance : NO

this is necessary for iOS 7, works for me. I do not know if there are some other techniques for doing this in iOS7. Set these two tags in your info.plist.

Everytime your viewcontroller appears, in viewDidLoad or when image picker controller finishes , use this:

 - (void) imagePickerController:(UIImagePickerController *)picker1 didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
   [[UIApplication sharedApplication] setStatusBarHidden:YES];
 .
 .
 .
 .
 }
metsburg
  • 2,021
  • 1
  • 20
  • 32
  • 1
    When you use image picker the status bar fades in... but when you are done using it, this code just hides it instantly... I would suggest using the following code to add a fade out animation to your status bar dismissal. `[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];` – Albert Renshaw Dec 13 '13 at 18:49
  • Also! Do NOT forget to put that code (either his or mine) in your `- (void)imagePickerControllerDidCancel:(UIImagePickerController*)picker {` as well! In case the user clicks "cancel" and doesn't pick a photo! – Albert Renshaw Dec 13 '13 at 18:50
6

I used Silvertaurus's answer above, but with a little modification to the prefersStatusBarHidden method that I thought was very helpful:

//UIImagePickerController+StatusBarHidden.h
#import <UIKit/UIKit.h>

@interface UIImagePickerController (StatusBarHidden)
@end

//UIImagePickerController+StatusBarHidden.h
#import "UIImagePickerController+StatusBarHidden.h"

@implementation UIImagePickerController (StatusBarHidden)

-(BOOL) prefersStatusBarHidden {
    if (self.sourceType==UIImagePickerControllerSourceTypeCamera) {
        return YES;
    } else {
        return NO;
    }
}

-(UIViewController *) childViewControllerForStatusBarHidden {
    return nil;
}

@end

This keeps the status bar up for the image picker when the camera is not displayed.

jbg7474
  • 61
  • 1
  • 1
1

Try this

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

Also check this discussion.

Community
  • 1
  • 1
Adarsh V C
  • 2,314
  • 1
  • 20
  • 37
1

Please try this.

• Setting a delegate for the UIImagePickerController

• 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:YES];
}
Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143
Ganesh
  • 524
  • 1
  • 4
  • 16
1

You can do it with a category:

@interface UIImagePickerController (HideStatusBar)

@end


@implementation UIImagePickerController (HideStatusBar)

- (BOOL)prefersStatusBarHidden
{
    return YES;
}

- (UIViewController *)childViewControllerForStatusBarHidden
{
    return nil;
}

@end

Source: https://gist.github.com/psobko/9493473

kanobius
  • 756
  • 9
  • 12
  • I'd recommend taking this same approach in a subclass instead, but this method definitely works! Thank you! – Sam Soffes Jul 09 '17 at 15:55
0
-(IBAction)takePhoto:(UIButton *)sender
{
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.allowsEditing = YES;
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    [self statusBar:TRUE];
    [self presentViewController:picker animated:YES completion:NULL];
}


-(void)imagePickerController:(UIImagePickerController *)picker      didFinishPickingMediaWithInfo:(NSDictionary *)info
{        
    UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
    self.imageView.image = chosenImage;
    [self statusBar:FALSE];
    [picker dismissViewControllerAnimated:YES completion:NULL];
}


-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [self statusBar:FALSE];
    [picker dismissViewControllerAnimated:YES completion:NULL];
}


-(void)statusBar:(BOOL)status
{
    [[UIApplication sharedApplication] setStatusBarHidden:status];
}

that might help you to achieve what you want.

D-eptdeveloper
  • 2,430
  • 1
  • 16
  • 30
0

Try my answer posted here if you want to keep using ViewController-Based Status Bar Appearance.

Community
  • 1
  • 1
voxlet
  • 311
  • 2
  • 8
0

In my case I had to use presentViewController to show UIImagePickerViewController (iOS7).

1- Set View controller-based status bar appearance to NO in .plist 2- Create a category for UIImagePickerController and in viewDidLayoutSubviews:

- (void)viewDidLayoutSubviews{
    [super viewDidLayoutSubviews];
    [[UIApplication sharedApplication] setStatusBarHidden:YES];
}

3- Added the two following methods to the category:

- (BOOL)prefersStatusBarHidden{
    return YES;
}

- (UIViewController *)childViewControllerForStatusBarHidden{
    return nil;
}

I hope this will help.

Ayoub Khayati
  • 121
  • 1
  • 6
0

i think i solved this in a pretty simple way without subclassing and using plist. it only hides for UIImagePickerController.

this example is for bringing up the photo gallary only, but i imagine you can apply it in the same way to anywhere with in uiimagepickercontroller

- (void)showGallary
{
  [CATransaction begin];
  [CATransaction setCompletionBlock:^{
      [[UIApplication sharedApplication] setStatusBarHidden:YES];
      [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
  }];

  imgPicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;

  [CATransaction commit];
}
greenhouse
  • 1,231
  • 14
  • 19