HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了我在使用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];
    }];
}

大佬总结

以上是大佬教程为你收集整理的我在使用UIImagePickerController时出现iOS 7 StatusBar问题允许编辑全部内容,希望文章能够帮你解决我在使用UIImagePickerController时出现iOS 7 StatusBar问题允许编辑所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。