UIImagePickerController隐藏statusBar

直接上代码;对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

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值