直接上代码;对UIImagePickerController扩展:
//
// UIImagePickerController+StatusBarHidden.m
//
//
// Created by fangmi-huangchengda on 15/7/28.
//
//
#import "UIImagePickerController+StatusBarHidden.h"
#import <objc/runtime.h>
@implementation UIImagePickerController (StatusBarHidden)
- (void)viewDidLoad
{
[super viewDidLoad];
[self setHidetatusBar:YES];
[self performSelector:@selector(hideStatusBar) withObject:nil afterDelay:0.5];
}
- (BOOL)prefersStatusBarHidden
{
if ([self hidetatusBar]) {
BOOL hide = (self.sourceType== UIImagePickerControllerSourceTypeCamera)? YES : NO;
return hide;
}
return NO;
}
- (UIViewController *)childViewControllerForStatusBarHidden
{
if ([self hidetatusBar]) {
return nil;
}
return [self.childViewControllers lastObject];
}
- (void)setHidetatusBar:(BOOL)hidetatusBar
{
objc_setAssociatedObject(self, (__bridge const void *)(@"hidetatusBar"), [NSNumber numberWithBool:hidetatusBar], OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
-(BOOL)hidetatusBar
{
NSNumber *hidetatusBar = objc_getAssociatedObject(self, (__bridge const void *)(@"hidetatusBar"));
return [hidetatusBar boolValue];
}
- (void)hideStatusBar
{
[self setHidetatusBar:YES];
[self prefersStatusBarHidden];
if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) {
[self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
}
}
- (void)showStatusBar
{
[self setHidetatusBar:NO];
[self prefersStatusBarHidden];
if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) {
[self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
}
}
@end
最后需要配置info.plist设置“View controller-based status bar appearance”为 NO