Search code examples
iosobjective-ciphoneios7statusbar

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?


Solution

  • 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