如何完全隐藏状态栏在iOS使用Cordova? [英] How to completely hide the status bar in iOS using Cordova?

查看:268
本文介绍了如何完全隐藏状态栏在iOS使用Cordova?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要开发的Cordova应用程式没有状态列。我几乎在那里,状态栏不显示在启动画面上。



我在Xcode中选中了隐藏状态栏复选框。

/ p>

我已经添加了 cordova-plugin-statusbar 插件和 deviceready callback,我调用 StatusBar.hide()



消失并且正在渲染第一页时,在显示页之前存在状态栏的闪光。



任何人都知道状态栏可以完全隐藏,而不会在隐藏之前闪烁?

解决方案

虽然我很晚才回答这个问题,但是一整天的搜索后,我得到这个工作,所以我想分享它



根据 docs (而且像 jcesarmobile 回答的):


隐藏启动



在运行时你可以使用下面的StatusBar.hide函数,但是如果
你想要StatusBar隐藏应用程序启动时,您必须修改
您应用程序的Info.plist文件。



如果不存在,请添加/编辑这两个属性。将状态栏是
初始隐藏设置为是,并将将基于控制器的状态栏
外观设置为否。如果您在不使用Xcode的情况下手动编辑它,则键
和值为:


这需要您修改应用程序的< c $ c> info.plist 文件 platforms / ios /< app-name> /< app-name> --Info.plist 文件添加以下行:

 < key> UIStatusBarHidden< / key> 
< true />
< key> UIViewControllerBasedStatusBarAppearance< / key>
< false />

但是不建议这样做,因为这将要求您保存该更改,这可能会在构建过程后被覆盖。因此,作为干净的替代品,您应该使用 cordova-custom-config



根据文档:


为什么要使用?



虽然一些平台首选项可以通过
Cordova / Phonegap在config.xml中设置,但许多(特别是与
更新的平台版本相关的)不能。一个解决方案是手动编辑platforms /目录中的
配置文件,但这不是可跨多个开发机器维护的
或CI环境
,后续构建操作可能会覆盖您的更改。 / p>

此插件尝试通过允许在准备操作
完成后设置额外的
特定于平台的首选项来解决此缺陷,允许优先设置由Cordova重写
或设置其他未指定的首选项。由于
自定义首选项被输入到config.xml,它们可以是
提交到版本控制,因此应用于多个
开发机器,CI环境,并在构建之间维护
或者删除并重新添加平台。


现在,您需要做的就是运行以下命令cordova应用程式:

  cordova外挂程式add cordova-custom-config --save 
/ pre>

并将其添加到< platform name下的 config.xml =ios> 块:

 < config-file parent =UIStatusBarHiddenplatform =iostarget =*  -  Info.plist> 
< true />
< / config-file>
< config-file parent =UIViewControllerBasedStatusBarAppearanceplatform =iostarget =* - Info.plist>
< false />
< / config-file>


I want to have no status bar for the Cordova app I am developing. I am nearly there, the status bar doesn't show on the splash screen. However on the first page that loads you see a flash of the status bar, before it gets hidden.

I have checked the "hide status bar" checkbox in Xcode.

I have added the cordova-plugin-statusbar plugin, and on the deviceready callback, I'm calling StatusBar.hide().

However when the splash image disappears and the first page is being rendered there is a flash of status bar prior to the page being display. It is only for a split second but looks awful.

Anybody know how the status bar can be hidden completely, without flashing up before being hidden?

解决方案

Although I'm answering this question very late but after one full day of the search, I got this working simply so I would like to share it with others.

According to the docs (and like jcesarmobile answered):

Hiding at startup

During runtime you can use the StatusBar.hide function below, but if you want the StatusBar to be hidden at app startup, you must modify your app's Info.plist file.

Add/edit these two attributes if not present. Set "Status bar is initially hidden" to "YES" and set "View controller-based status bar appearance" to "NO". If you edit it manually without Xcode, the keys and values are:

This requires you to modify your app's info.plist file inside platforms/ios/<app-name>/<app-name>-Info.plist file to add the following lines:

<key>UIStatusBarHidden</key>
<true/>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>

But that is not recommended because this will require you to save that change which might get overwritten after build process. So as the clean alternative you should use cordova-custom-config.

According to docs:

Why should I use it?

While some platform preferences can be set via Cordova/Phonegap in the config.xml, many (especially ones related to newer platform releases) cannot. One solution is to manually edit the configuration files in the platforms/ directory, however this is not maintainable across multiple development machines or a CI environment where subsequent build operations may overwrite your changes.

This plugin attempts to address this gap by allowing additional platform-specific preferences to be set after the prepare operation has completed, allowing either preferences set by Cordova to be overridden or other unspecified preferences to be set. Since the custom preferences are entered into the config.xml, they can be committed to version control and therefore applied across multiple development machines, CI environments, and maintained between builds or even if a platform is removed and re-added.

Now, all you have to do is to run the following command for your cordova app:

cordova plugin add cordova-custom-config --save

And add this to your config.xml file under <platform name="ios"> block:

<config-file parent="UIStatusBarHidden" platform="ios" target="*-Info.plist">
    <true/>
</config-file>
<config-file parent="UIViewControllerBasedStatusBarAppearance" platform="ios" target="*-Info.plist">
    <false/>
</config-file>

这篇关于如何完全隐藏状态栏在iOS使用Cordova?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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