离子空白模板默认隐藏配件栏不起作用

时间:2015-05-15 16:51:21

标签: javascript ionic-framework statusbar

嗨,我开始了一个空白的离子项目。在app.js文件中有以下代码:

// Ionic Starter App

// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
angular.module('starter', ['ionic'])

.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
    // for form inputs)
    if(window.cordova && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
    }
    if(window.StatusBar) {
      StatusBar.styleDefault();
    }
  });
})

据我所知,上面的代码确实做了两件事。它隐藏了键盘上方的配件栏。并将状态栏样式设置为默认样式。

看起来两者似乎都不起作用。当我测试我的应用程序时,配件栏上的离子视图应用程序仍在那里。

当我从

更改状态栏样式代码的部分时
  

StatusBar.styleDefault();

  

StatusBar.overlaysWebView(真); StatusBar.styleLightContent();

状态栏仍然是默认样式(黑暗),我想拥有灯光样式状态栏。

我做错了什么,我错过了什么,或者我是否理解上面的错误代码
谢谢!

config.xml中:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<widget id="com.ionicframework.testapp582099" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
  <name>test_app</name>
  <description>
        An Ionic Framework and Cordova project.
    </description>
  <author email="hi@ionicframework" href="http://ionicframework.com/">
      Ionic Framework Team
    </author>
  <content src="index.html"/>
  <access origin="*"/>
  <preference name="webviewbounce" value="false"/>
  <preference name="UIWebViewBounce" value="false"/>
  <preference name="DisallowOverscroll" value="true"/>
  <preference name="BackupWebStorage" value="none"/>
  <feature name="StatusBar">
    <param name="ios-package" value="CDVStatusBar" onload="true"/>
  </feature>
</widget>

1 个答案:

答案 0 :(得分:1)

添加插件后它应该可以工作:

$ cordova plugin add org.apache.cordova.statusbar

由于某些原因,即使在代码中使用了插件,插件也不会自动安装在Ionic入门项目中。更多信息:http://learn.ionicframework.com/formulas/customizing-the-status-bar/

要在Ionic View中使用此功能,您可能需要做更多工作。

  • 安装ngCordova:http://ngcordova.com/docs/install/。确保ng-cordova.jsangular.jscordova.js之间生活。如果你想使用更多的ngCordova插件,这无论如何都不是很糟糕。
  • 注入角度依赖项angular.module('myApp', ['ngCordova'])
  • 运行$ cordova plugin add cordova-plugin-statusbar。首先要删除上面的插件(它们可能也可能不一样......)。
  • $cordovaStatusbar注入.run块(如果需要,还可以注入控制器等)。
  • 像以前一样使用,但同样如此:$cordovaStatusbar.hide()
  • 如果您的代码位于$ionicPlatform.ready,则可能无法在Ionic View中按预期工作(请参阅:https://github.com/driftyco/ionic-view-issues/issues/52)。要使其正常工作,请将其包装在$timeout中,或者
      

    因此,如果您对小型黑客不感兴趣,则在离子加载之前将<script>window.phonegap = {}</script>添加到您的<head>应该强制它等待设备已准备好的事件而不会踩到Cordova&#39; s一旦它加载了脚趾。比在任何地方写$ timeout都简单得多。