Skip to content

Instantly share code, notes, and snippets.

@situee
Forked from Marlunes/hide_status_bar
Last active December 24, 2015 01:19
Show Gist options
  • Select an option

  • Save situee/6723108 to your computer and use it in GitHub Desktop.

Select an option

Save situee/6723108 to your computer and use it in GitHub Desktop.
//viewDidload
if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) {
// iOS 7
[self prefersStatusBarHidden];
[self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
} else {
// iOS 6
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
}
// Add this Method
- (BOOL)prefersStatusBarHidden
{
return YES;
}
@situee
Copy link
Author

situee commented Sep 27, 2013

iOS7 hide status bar; "prefersStatusBarHidden" is callback (delegate) method

@situee
Copy link
Author

situee commented Sep 27, 2013

https://devforums.apple.com/message/888605#888605
by Tobias Arends

There are two different cases depending on the value of View controller-based status bar appearance in your info.plist. The default value is YES.

First Case:
Set View controller-based status bar appearance in your info.plist to NO.

You can use:

[[UIApplication sharedApplication] setStatusBarHidden:NO];

You would Implement the following to achieve the hidden statusBar:

-(void)takePhotoPressed{

    UIImagePickerController *picker = [[UIImagePickerController alloc] init];

    picker.delegate = self;

    if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])

        return;

    picker.sourceType = UIImagePickerControllerSourceTypeCamera;

    [self presentViewController:picker animated:YES completion:^{

        [[UIApplication sharedApplication] setStatusBarHidden:YES];

    }];

}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{

    [self dismissViewControllerAnimated:YES completion:^{

           [[UIApplication sharedApplication] setStatusBarHidden:NO];

    }];
}

Second Case:
If you set View controller-based status bar appearance in your info.plist to YES. (Or you don't set it at all. It will default to YES)

This seems to be a very bad idea. But it does work.

Create a Category on UIViewController and override prefersStatusBarHidden to always return YES.
You can still override it to return NO in every ViewController in which you want to display the StatusBar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment