12

This is a rather unique question. I have searched for hours and could not find the answer. I want ALL UIViewControllers in my app to have the UIStatusBar visible. But on a certain UIViewController, when you tap a UIButton, the following method calls the camera modalView controller. I want to hide the status bar when the following method is called:

-(BOOL)startCameraControllerFromViewController:(UIViewController*)controller
                                 usingDelegate:(id )delegate 

I have tried changing the plist file with UIViewController based status bar = YES (I only want the UIStatusBar hidden when that modal view is pulled up)

I have also tried the following within the above method:

[[UIApplication sharedApplication] setStatusBarHidden:YES 
                                   withAnimation:UIStatusBarAnimationNone];
if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) {

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

Nothing seems to work. Can anyone help?

Josue Espinosa
  • 5,009
  • 16
  • 47
  • 81
  • Check this answer out: http://stackoverflow.com/questions/19774968/under-ios-7-how-do-i-hide-and-show-status-bar-on-the-fly-whenever-i-want-to/19867698#19867698 – John Riselvato Feb 20 '14 at 16:59

5 Answers5

16

Implement this method in your View Controller,

-(BOOL)prefersStatusBarHidden
{
    return YES;
}

and call this method where you want,

[self prefersStatusBarHidden];
karthika
  • 4,085
  • 3
  • 21
  • 23
  • This is what I want, but ONLY when the modal view is active. I don't have a separate class for that view, its on the same class as the parent controller. This only hides it for the parent controller. When the child is pulled up, it fades in. – Josue Espinosa Oct 04 '13 at 05:47
  • i can't understand exactly what you want. you call this method, when the modal view is active and check if the model view is active, return yes otherwise return No.if(modalView)return YES else return NO. – karthika Oct 04 '13 at 05:51
  • That _is_ what I am doing, but it only does it for the parent controller. It has no effect on the modal view. – Josue Espinosa Oct 04 '13 at 05:57
  • Try this, http://stackoverflow.com/questions/14551583/check-the-ios-status-bar-hidden-with-a-modal-view-controller – karthika Oct 04 '13 at 06:04
16

Solved it by subclassing the UIImagePickerController and just adding this to the .m file:

- (BOOL)prefersStatusBarHidden {
    return YES;
}

then importing it to the class that uses the picker, and instead of initializing the imagepicker i initialize the subclass.

NOTE: make sure View controller-based status bar appearance is set to YES in your plist file.

Josue Espinosa
  • 5,009
  • 16
  • 47
  • 81
  • Not working, are you sure these are the only changes you've made? p.s. it's not UIImagePicker it's UIImagePickerController – ozba Feb 16 '14 at 23:04
  • Positive. Make sure when you alloc, init the UIImagePickerController, you do that to use your subclass instead. – Josue Espinosa Feb 20 '14 at 16:58
3

What you can do also is to set the status bar hidden in the plist as you did before. Then you call setStatusBarHidden:NO in the app delegate to set it as default value when the app first load. And then you call this method again where you need to hide the status bar with the value YES.

Thibaut Rey
  • 318
  • 2
  • 5
0

Have successfully used -(BOOL)prefersStatusBarHidden{...} for numerous view controllers but it did not on a particular modal view presented without a Navigation Controller. As per Karthika I had success with Check the iOS status bar hidden with a modal view controller.

Community
  • 1
  • 1
user3000868
  • 455
  • 4
  • 13
0
-(void)viewWillApper:(BOOL)animated{
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
-(void)viewWillDisappear:(BOOL)animated{
[[UIApplication sharedApplication] setStatusBarHidden:NO];
}

This code will set viewcontroller which you want to hide status bar.

Tharoth
  • 383
  • 5
  • 15