如何使用 Phonegap Build 删除 iOS 状态栏?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20734117/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 22:50:51  来源:igfitidea点击:

How to remove iOS status bar with Phonegap Build?

ioscordovastatusbarphonegap-build

提问by Per Quested Aronsson

Is it possible to get rid of the status bar in iOS7 when using Phonegap Build 3.1? I can remove the status bar when building locally in Xcode, but as soon as I try Phonegap Build, it's back again.

使用Phonegap Build 3.1时是否可以摆脱iOS7中的状态栏?在 Xcode 本地构建时,我可以删除状态栏,但是一旦我尝试使用 Phonegap Build,它就会再次返回。

  1. Is there a config preference to remove the status bar completely?
  2. If not, is it possible to overlay the status bar on top of the app view and set it to a transparent background?
  1. 是否有配置首选项可以完全删除状态栏?
  2. 如果没有,是否可以将状态栏覆盖在应用程序视图的顶部并将其设置为透明背景?

I do notwant the status bar to push down the app view 20px, which is the case now.

希望状态栏将应用视图下推 20px,现在就是这种情况。

回答by Minifyre

As of Phonegap 3 you can now customize plistfiles via config.xml.

从 Phonegap 3 开始,您现在可以通过 config.xml自定义 plist文件。

Code:

代码:

<gap:config-file platform="ios" parent="UIViewControllerBasedStatusBarAppearance" overwrite="true">
    <false/>
</gap:config-file>

回答by myaug

Add this function into MainViewController.m file:

将此函数添加到 MainViewController.m 文件中:

//fix not hide status on ios7
- (BOOL)prefersStatusBarHidden
{
    return YES;
}

回答by MPaulo

Usually, you would edit the info.plist and add this key:

通常,你会编辑 info.plist 并添加这个键:

 <key>UIViewControllerBasedStatusBarAppearance</key><false/>

But as you can't do this on build, you'll have to add a plugin:

但是由于您无法在构建时执行此操作,因此您必须添加一个插件:

https://github.com/phonegap-build/StatusBarPlugin/blob/master/README.md

https://github.com/phonegap-build/StatusBarPlugin/blob/master/README.md

And then:

进而:

StatusBar.hide();

状态栏.hide();

回答by mrMaF

click on the "projectname-Info.plist"file under the XCode root project folder , you will be shown with an UI where you can see key vs values entries ,you can add/delete keys, add a new key just look for "Status bar is initially hidden"and set "YES" as the value.

单击XCode 根项目文件夹下的“projectname-Info.plist”文件,您将看到一个 UI,您可以在其中看到键与值条目,您可以添加/删除键,添加新键只需查找“状态” bar 最初是隐藏的”并将“是”设置为值。

回答by pppontusw

I'm using the following in config.xml which completely removes the status bar, tested on iOS 7.0.3 & 7.0.4, Phonegap version 3.0.0 if that helps.

我在 config.xml 中使用了以下内容,它完全删除了状态栏,在 iOS 7.0.3 和 7.0.4、Phonegap 3.0.0 版上测试,如果有帮助的话。

    <preference name="fullscreen" value="true" />

回答by Dima

With Cordova, I had to do actually 2 things.

对于 Cordova,我实际上必须做两件事。

  1. When I build with XCode I set in Target->Statusbar style to -> HIDDEN this would hide statusbar at startup on your splash screen.

  2. You have to hide it also on device ready with plugin. Otherwise, it will reappear. To do that, install plugin:

  1. 当我使用 XCode 构建时,我将 Target->Statusbar 样式设置为 -> HIDDEN 这将在启动屏幕上隐藏状态栏。

  2. 您还必须在准备好插件的设备上隐藏它。否则,它会再次出现。为此,请安装插件:

cordova plugin add org.apache.cordova.statusbar

cordova plugin add org.apache.cordova.statusbar

and call this on deviceready:

并在 deviceready 上调用它:

StatusBar.hide();

回答by occasl

Simply install the status bar plugin (I'm using Cordova 5.x):

只需安装状态栏插件(我使用的是 Cordova 5.x):

cordova plugin add [email protected]

The in your code just reference its global variable and use .hide():

在您的代码中只引用其全局变量并使用 .hide():

StatusBar.hide()

回答by Juan Camilo Guarin P

This worked for me:

这对我有用:

<preference name="fullscreen" value="true" />

I'm working on Android.

我在安卓上工作。

回答by allwynmasc

I've answered this for removingthe Status bar altogether in your previous question

我已经回答了这个问题,因为在您之前的问题中完全删除了状态栏

The essential part:

必不可少的部分:

I got this to work beautifully in Cordova 3.6 + iOS 7.1. And considering that iOS 7 and 8 each have 50% of market share this solution should be enough.

我让它在 Cordova 3.6 + iOS 7.1 中工作得很好。考虑到 iOS 7 和 8 各占 50% 的市场份额,这个解决方案应该足够了。

Plugin I'm using: org.apache.cordova.statusbar

我正在使用的插件: org.apache.cordova.statusbar

Instead of using StatusBar.hide()I used:

而不是使用StatusBar.hide()我使用:

var hideSb = function(){
//        StatusBar.hide;
        cordova.exec(null, null, 'StatusBar', 'hide', ['Ehi', 'You']);
    };