Pregunta

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?

¿Fue útil?

Solución 2

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.

Otros consejos

Implement this method in your View Controller,

-(BOOL)prefersStatusBarHidden
{
    return YES;
}

and call this method where you want,

[self prefersStatusBarHidden];

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.

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.

-(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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top