7

I've tried setting the Info.plist 'View controller-based status bar appearance' to NO, I've tried calling

[[UIApplication sharedApplication] setStatusBarHidden:YES];

I've tried

-(BOOL)prefersStatusBarHidden{ 
  return YES;
}

I've tried launching the picker with

[self presentViewController:picker animated:NO completion:^{
  [[UIApplication sharedApplication] setStatusBarHidden:YES];
}

And still, there is a status bar overlapping the camera controls. It's only there in iOS 7 though.

The status bar doesn't show up any where else in the app. I feel like I'm missing an important piece of the puzzle here, and no amount of reading about the View Controller or UIImagePickerController has helped me find said puzzle piece.

I'm hoping some one else has a little insight into this problem. Thank you.

EDIT: My desired effect is that the Status Bar shows up every in the app, except on the camera picker and a few other "outside" (Email related) view controllers we use.

9 Answers9

17

If you want to keep ViewController-Based Status Bar Appearance, subclass UIImagePickerController and override prefersStatusBarHidden and childViewControllerForStatusBarHidden.

@interface NoStatusBarImagePickerController : UIImagePickerController
@end

@implementation NoStatusBarImagePickerController

- (BOOL)prefersStatusBarHidden {
  return YES;
}

- (UIViewController *)childViewControllerForStatusBarHidden {
  return nil;
}

@end
voxlet
  • 311
  • 2
  • 8
  • 4
    From the apple docs on UIImagePickerController: Important: The UIImagePickerController class supports portrait mode only. This class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified, with one exception. You can assign a custom view to the cameraOverlayView property and use that view to present additional information or manage the interactions between the camera interface and your code. – alphanumeric character Feb 11 '14 at 00:08
  • So please stop upvoting this answer. – alphanumeric character Feb 11 '14 at 00:09
  • 2
    I'd agree if any of the picker methods were overridden, but only the base UIViewController behavior is customized, and in an intended manner. To each his own interpreting the docs, but I don't believe I'm violating any rules in spirit, and I certainly hope Apple's SDK implementation is at least well behaved enough in terms of encapsulation that this is acceptable. – voxlet Feb 14 '14 at 14:22
  • Well, regardless of violating the spirit of the docs or not, it still didn't work to fix my issue. Thanks for your suggestion though - it was a worthy attempt! – alphanumeric character Feb 18 '14 at 17:35
  • **IT WORKS** ... Alpha, I have to absolutely agree with masmor. This is "not really" subclassing. You're not in the slightest changing anything in the class. You are only - let's put it this way - "changing a preference" regarding the view controller. This is an incredible answer, masmor, thank you. Really, thanks. – Fattie Feb 28 '14 at 14:59
  • **IT DOES ACTUALLY WORK!!** :) This is awesome. Interestingly **YOU DO NEED** the childViewControllerForStatusBarHidden method, it will not work otherwise. And again you **DO NOT NEED** (and should not add) UIViewControllerBasedStatusBarAppearance in your plist. THANKS AGAIN – Fattie Feb 28 '14 at 15:33
  • @alphanumericcharacter what about using a category instead? – psobko Mar 11 '14 at 19:46
  • Yeah, NOTHING we tried sorted this problem out. I've seen a few, and far between references from other people just as frustrated as I am about this. It's really looking like an iOS bug, although it's not clear how to reliably reproduce it. Several other developers in my organization had a look at this, and each of them tried all the various ways of fixing it, without luck. Sadly, I think the answer is here "If you can't fix it with the few easy methods, then buck up and deal with it, because you can't fix it." – alphanumeric character Mar 13 '14 at 23:29
  • I found this solution causes the animation for the picker to become buggy. In the simulator it freezes at 1/4 of the way in. On the device the animation isn't smooth. – divergio Jul 11 '14 at 09:33
7

Try this :

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

in your appDelegate.

Alexandru Dranca
  • 830
  • 1
  • 7
  • 21
  • Second line up above: I tried that in my app delegate, without success. – alphanumeric character Sep 23 '13 at 18:49
  • 1
    @alphanumericcharacter You my try adding this in your class implementing UIImagePickerDelegate. This is actually a method of UINavigationControllerDelegate. – Abduliam Rehmanius Oct 01 '13 at 16:33
  • 3
    This solution works for me but you have to add this UINavigationControllerDelegate method in that class in which you are implementing UIImagePickerDelegate and here you go. – prakhar Oct 07 '13 at 07:40
3

There's an additional setting you need to turn on, starting in iOS 7. In your app's Info.plist, add a line for View controller-based status bar appearance, a Boolean, and set it to NO.

Aaron Golden
  • 7,092
  • 1
  • 25
  • 31
  • 2
    Bug in iOS 7, you must hide the status bar when you dismiss the image picker. Make a subclass and put it in viewWillDisappear. – jjxtra Sep 22 '13 at 03:06
  • I don't want the status bar present on the UIImagePickerController. I *DO* want it in my app. I have tried subclassing the UIImagePickerController, but perfersStatusBarHidden never gets called, and the status bar still shows up. – alphanumeric character Sep 23 '13 at 18:35
  • You definitely should not do this. That setting is only for sort of weird backwards compatibility with ancient iOS. It will cause huge problems. Simply do masmor's solution: it is extremely simple. Just click "new File..." and choose "Objective C Class..." in Xcode .. takes 5 seconds. – Fattie Feb 28 '14 at 15:02
1

The PsychoDad method works for me. I put the following

[[UIApplication sharedApplication] setStatusBarHidden:YES];

into the method viewWillDisappear of subclass of UIImagePickerController.

But the Alexandru Dranca method is better because in that way the status bar don't appear at all!

However I think this is a BUG of IOS 7...

Community
  • 1
  • 1
Magurizio
  • 300
  • 2
  • 10
0

"View controller-based status bar appearance" set to NO, works for me.

JerryZhou
  • 4,566
  • 3
  • 37
  • 60
  • did you set programetically? – Jignesh B Oct 30 '13 at 11:36
  • @JigPatel No,it's in 'p-list' file – JerryZhou Nov 08 '13 at 01:35
  • I WANT the status bar every where in my app, except in the UIImagePickerController. I can't keep it from showing up there, and it overlaps the picker controls. Also, I've tried setting this in the info.plist, and while it DID remove the status bar from every where in my app, I wasn't able to get it to show, even with using some of the other methods that should make it appear. I tend to agree that this is an iOS7 bug. – alphanumeric character Feb 11 '14 at 00:13
0

you should leave the

-(BOOL)prefersStatusBarHidden{ 
  return YES;
}

and also add this

-(void)viewWillAppear:(BOOL)animated {
    ...
    [self setNeedsStatusBarAppearanceUpdate];
    ...
}
mike
  • 31
  • 2
0

I've been on this bug for repairing ToonPAINT for iOS7 and the thing that finally worked other than setting the two things in the Info.plist file (Status bar is initially hidden = NO; View controller-based status bar appearance = NO)

was to change the style of the status bar (even though I didn't want it shown at all); It was not enough to just hide the status bar; sounds like an iOS7 bug.

In the app delegate add:

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

{NB .. UIStatusBarStyleBlackTranslucent is deprecated, probably use UIStatusBarStyleLightContent if trying this}

Fattie
  • 27,874
  • 70
  • 431
  • 719
user1435707
  • 111
  • 1
  • 6
0

I think the answer to this question is "This is an iOS 7 bug". None of the methods here helped in our case, and several people have tried to fix this now.

I can't say what steps to reproduce this, but I've seen enough people out there with the same issue, that I think it's safe to say that this is in fact an iOS 7 bug. Most people can fix this problem with the multiple methods listed above. Rarely though, you can't fix it that way. I hope if you are reading this, you are not also one of those people.

0

This is what worked for me:

@implementation ViewController {
    BOOL hideStatusBar;
}

- (void)showCamera {
    UIImagePickerController *camera = [[UIImagePickerController alloc] init];
    camera.modalPresentationStyle = UIModalPresentationCurrentContext;
    camera.sourceType = UIImagePickerControllerSourceTypeCamera;
    camera.delegate = self;

     hideStatusBar = YES;
    [self setNeedsStatusBarAppearanceUpdate];
    [self presentViewController:camera animated:YES completion:nil];
}

-(BOOL)prefersStatusBarHidden{
    return hideStatusBar;
}
Erik Escobedo
  • 2,793
  • 24
  • 42