可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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?
回答1:
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//-Info.plist
file to add the following lines:
UIStatusBarHiddenUIViewControllerBasedStatusBarAppearance
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
block:
Please refer cordova-custom-config (version > 5) plugin for more information
Update 1 (20th Feb 2018)
If you are using cordova-custom-config plugin version custom-config-file tag with config-file
.
https://github.com/dpa99c/cordova-custom-config#changes-in-cordova-custom-config5
回答2:
EDIT:
Since Cordova CLI 6.5.0 you can use edit-config
tag to write in the info.plist without a plugin. This should hide the statusbar at startup
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:
UIStatusBarHiddenUIViewControllerBasedStatusBarAppearance
https://github.com/apache/cordova-plugin-statusbar
回答3:
回答4:
This way worked to me:
On your mac or VM xcode, select TARGETS->Your app
Then on INFO menu, on CUSTOM iOS TARGET PROPERTIES, add this NEW properties:
Statusbar is initially hidden -> Then set the value to YES.
View controller-based status bar appearance -> Then set the value to NO
Build and you should have no statusbar.
printscreen: http://prntscr.com/fg0jtf
回答5:
I was also having the same problem for android. It was solved by simply calling the below statusBar() function from the 'appCtrl' init() function.
Hope it will work for iOS.
$rootScope.statusBar = function(){ document.addEventListener("deviceready", onDeviceReady, false); function onDeviceReady() { //console.log(StatusBar); StatusBar.hide(); }