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
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
If you want to disable the status bar from plist, try this:
this is necessary for iOS 7, works for me. I do not know if there are some other techniques for doing this in iOS7. Set these two tags in your info.plist.
Everytime your viewcontroller appears, in viewDidLoad or when image picker controller finishes , use this:
- (void) imagePickerController:(UIImagePickerController *)picker1 didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
[[UIApplication sharedApplication] setStatusBarHidden:YES];
.
.
.
.
}
I used Silvertaurus's answer above, but with a little modification to the prefersStatusBarHidden
method that I thought was very helpful:
//UIImagePickerController+StatusBarHidden.h
#import <UIKit/UIKit.h>
@interface UIImagePickerController (StatusBarHidden)
@end
//UIImagePickerController+StatusBarHidden.h
#import "UIImagePickerController+StatusBarHidden.h"
@implementation UIImagePickerController (StatusBarHidden)
-(BOOL) prefersStatusBarHidden {
if (self.sourceType==UIImagePickerControllerSourceTypeCamera) {
return YES;
} else {
return NO;
}
}
-(UIViewController *) childViewControllerForStatusBarHidden {
return nil;
}
@end
This keeps the status bar up for the image picker when the camera is not displayed.
Please try this.
• Setting a delegate for the UIImagePickerController
• hide the status bar in the delegate's navigationController:didShowViewController:animated: function.
E.G:
-(void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
subclass UIImagePickerController ... mine is V1ImagePickerController ...
.m file looks like this:
#import "V1ImagePickerController.h"
@interface V1ImagePickerController ()
@end
@implementation V1ImagePickerController
- (void)viewDidLoad
{
[super viewDidLoad];
if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) // iOS7+ only
{
self.edgesForExtendedLayout = UIRectEdgeNone;
[self prefersStatusBarHidden];
[self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
}
}
- (BOOL)prefersStatusBarHidden
{
return YES;
}
- (UIViewController *)childViewControllerForStatusBarHidden
{
return nil;
}
@end
the childViewControllerForStatusBarHidden is the key!
Try this
[[UIApplication sharedApplication] setStatusBarHidden:NO animated:NO];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent animated:YES];
Also check this discussion.