码迷,mamicode.com
首页 > 其他好文 > 详细

UIImagePickerController隐藏statusBar

时间:2015-07-28 18:46:01      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:ios

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

版权声明:本文为博主原创文章,未经博主允许不得转载。

UIImagePickerController隐藏statusBar

标签:ios

原文地址:http://blog.csdn.net/isalvador/article/details/47107057

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!