Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide status bar in UIImagepickercontroller?

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?

like image 425
Shailendra Kumar Gangwar Avatar asked Sep 12 '13 09:09

Shailendra Kumar Gangwar


2 Answers

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.

like image 196
Alexandru Dranca Avatar answered Oct 20 '22 06:10

Alexandru Dranca


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

like image 33
Silvertaurus Avatar answered Oct 20 '22 06:10

Silvertaurus