检查使用模态视图控制器隐藏的iOS状态栏 [英] Check the iOS status bar hidden with a modal view controller

查看:112
本文介绍了检查使用模态视图控制器隐藏的iOS状态栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在Xcode中使用实用程序应用程序"模板,并具有主视图控制器,用户可以在其中使用按钮隐藏和显示状态栏.我还获得了 Flipside View Controller ,它使用了模态搜索,其中有一个完成按钮可以返回到 Main VC .我进行了设置,以便每当查看 Flipside VC 时,状态栏始终不会被隐藏.这意味着,如果用户在主VC 上隐藏状态栏并转换为 Flipside VC ,它将进行动画处理,并且用户没有隐藏状态栏并且它们过渡时,状态栏什么也没发生.

so i'm using the "Utility Application" template in Xcode and have the Main View Controller, where the user can hide and show the status bar using a button. I've also got the Flipside View Controller, using a modal segue, which has a done button to return to the Main VC. I've set it up so that whenever viewing the Flipside VC, the status bar is always NOT hidden. This means that if the user hides the status bar on the Main VC and transitions to the Flipside VC, it will animate on and if the user didn't hide the status bar and they transition, nothing happens to the status bar.

这很好,问题正在从 Flipside VC 过渡到 Main VC .我需要一个条件来检查主VC 中状态栏的隐藏状态,按下完成按钮时会在 Flipside VC 中调用它.

That's all good, the problem is transitioning back from the Flipside VC to Main VC. I need a condition to check the hidden state of the status bar in the Main VC, which would be called in the Flipside VC when pressing the done button.

我一直在研究使用BOOL以及NSNotificationCenter将有关状态栏状态的消息发送到 Flipside VC .

I've looked into using a BOOL as well as NSNotificationCenter to send a message to the Flipside VC about the state of the status bar.

我有以下代码:

-(BOOL)checkStatusBarHidden:(id)input
{
    BOOL result;

    if ([UIApplication sharedApplication].statusBarHidden = YES)
    {
        result = YES;
    }
    else
    {
        result = NO;
    }

    return result;
}

但这只是猜测,我可能可以在某个地方使用它来通知 Flipside VC 状态栏状态.我想到可能要改变

But this is all just guessing and thinking I might be able to use it somewhere to inform the Flipside VC of the status bar state. I thought of maybe changing the

[UIApplication sharedApplication].statusBarHidden = YES)

类似

self.statusBarHidden = YES //which of course isn't going to work

但是无论如何,正如我所说的那样,我不确定该怎么办.

But anyway, as I said it's guessing and i'm not sure what to do.

推荐答案

您可能会考虑使用属性(例如,

You may think of storing the information about the status bar state in the MainViewController using a property, e.g.

@property (nonatomic, assign) BOOL statusBarHidden;

然后您可以使用presentingViewController属性从FlipsideViewController访问该值.

then you can access that value from the FlipsideViewController using the presentingViewController property.

MainViewController * mainVC = self.presentingViewController;
if (mainVC.statusBarHidden) {
   // Do stuff
}

最后,请将您的checkStatusBarHidden:方法更改为类似的

As a final remark, please change your checkStatusBarHidden: method to something like

- (BOOL)checkStatusBarHidden {
    return [UIApplication sharedApplication].statusBarHidden;
}

这篇关于检查使用模态视图控制器隐藏的iOS状态栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆