我在使用UIImagePickerController时出现iOS 7 StatusBar问题允许编辑

前端之家收集整理的这篇文章主要介绍了我在使用UIImagePickerController时出现iOS 7 StatusBar问题允许编辑前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我研究相关的iOS 7状态 – Bar Maintain,但我在使用UI ImagePickerController时遇到了问题.允许编辑“编辑窗口”在顶部栏显示20像素空间.

我使用了代码,首先我在info.plist中将UIViewControllerBasedStatusBarAppearance设置为NO并设置委托方法

Appdelegate.h

@property (retain,nonatomic) UIWindow *background;

Appdelegate.m

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {

    [application setStatusBarStyle:UIStatusBarStyleLightContent];
    self.window.clipsToBounds =YES;
    self.window.frame =  CGRectMake(0,20,self.window.frame.size.width,self.window.frame.size.height-20);

    self.window.bounds = CGRectMake(0,self.window.frame.size.height);

    background = [[UIWindow alloc] initWithFrame: CGRectMake(0,20)];
    background.backgroundColor =[UIColor redColor];
    [background setHidden:NO];
}

在我的家庭视图控制器中没有任何效果,所以我放入了我的home viewController,一种用于更改状态栏背景颜色的方法

-(void)viewWillLayoutSubviews{

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
    self.view.clipsToBounds = YES;
    CGRect screenRect = [[UIScreen mainScreen] bounds];
    CGFloat screenHeight = screenRect.size.height;
    self.view.frame = CGRectMake(0,self.view.frame.size.width,screenHeight-20);
    self.view.bounds = CGRectMake(0,self.view.frame.size.height);

    UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];

    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"userIsMale"]) {
        [tempWindow setBackgroundColor:[UIColor colorWithRed:(46.0/255.0) green:(134.0/255.0) blue:(255.0/255.0) alpha:1]];
    }
    else {
        [tempWindow setBackgroundColor:[UIColor colorWithRed:(246.0/255.0) green:(26.0/255.0) blue:(113.0/255.0) alpha:1]];
    }

    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}

现在,当我呈现UIImagePickerController时,允许编辑窗口显示如下:

我尝试使用此解决方案为隐藏状态栏,同时呈现UIImagePickerController:

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    [[UIApplication sharedApplication] setStatusBarHidden:YES];
}

并在ViewWillApear中显示状态条形码.

我得到了这种结果:

我在哪里做错了,我该如何解决这个问题?

解决方法

尝试一下:
-(BOOL)prefeRSStatusBarHidden { return YES; }

它会隐藏状态栏.

在iOS 7上,如果要使用setStatusBarHidden :,则需要在info.plist中将基于View控制器的状态栏外观设置为NO.

我希望它会给你一些暗示.

编辑:

我发现了问题.

这是第一次在viewWillAppear上显示homeViewController时的日志:

(lldb) po [[UIApplication sharedApplication] windows]
<__NSArrayM 0x8a74560>(
<UIWindow: 0x8e33360; frame = (0 20; 320 548); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x8e348b0>; layer = <UIWindowLayer: 0x8e3c6e0>>,<UIWindow: 0x8c1db40; frame = (0 0; 320 20); gestureRecognizers = <NSArray: 0x8c1e170>; layer = <UIWindowLayer: 0x8c1da80>>
)

这是解雇imagePicker并调用viewWillAppear后的日志:

(lldb) po [[UIApplication sharedApplication] windows]
<__NSArrayM 0x8c1a700>(
<UIWindow: 0x8e33360; frame = (0 0; 320 568); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x8e348b0>; layer = <UIWindowLayer: 0x8e3c6e0>>,<UIWindow: 0x8c1db40; frame = (0 0; 320 20); gestureRecognizers = <NSArray: 0x8c1e170>; layer = <UIWindowLayer: 0x8c1da80>>,<UITextEffectsWindow: 0x8c53380; frame = (0 0; 320 568); hidden = YES; opaque = NO; gestureRecognizers = <NSArray: 0x8c538a0>; layer = <UIWindowLayer: 0x8c53520>>
)

默认窗口大小已更改.这就是状态栏无法显示的原因.

我编辑了这样的代码,它对我有用:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view,typically from a nib.
    //    [[UIApplication sharedApplication] setStatusBarHidden:YES];
    if(OVER_IOS7){
        [self.navigationController.navigationBar setTranslucent:NO];
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide];
}

-(void)viewWillLayoutSubviews{

    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
        self.view.clipsToBounds = YES;
        CGRect screenRect = [[UIScreen mainScreen] bounds];
        CGFloat screenHeight = screenRect.size.height;
        self.view.frame = CGRectMake(0,screenHeight-20);
        self.view.bounds = CGRectMake(0,self.view.frame.size.height);

        UIWindow *defaultWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:0];

        defaultWindow.frame =  CGRectMake(0,320,548);
        defaultWindow.bounds = CGRectMake(0,548);

        UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];

        if ([[NSUserDefaults standardUserDefaults] boolForKey:@"userIsMale"]) {
            [tempWindow setBackgroundColor:[UIColor colorWithRed:(46.0/255.0) green:(134.0/255.0) blue:(255.0/255.0) alpha:1]];
        }
        else {
            [tempWindow setBackgroundColor:[UIColor colorWithRed:(246.0/255.0) green:(26.0/255.0) blue:(113.0/255.0) alpha:1]];
        }

        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    }
}

- (IBAction)showImagePicker:(id)sender
{
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];

    [picker setSourceType:UIImagePickerControllerSourceTypeSavedPhotosAlbum];
    [self presentViewController:picker animated:YES completion:^{
        [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
    }];
}
原文链接:https://www.f2er.com/iOS/331330.html

猜你在找的iOS相关文章