【问题标题】:iOS status bar overlapping contentsiOS 状态栏重叠内容
【发布时间】:2016-01-01 21:22:17
【问题描述】:

我已经构建了 phonegap 应用程序,它在 android 和 windows 上运行良好。 但是对于 iOS,我面临的问题是,状态栏内容和页面内容混合在一起,因此我无法点击标题中提供的后退按钮。 任何人都可以帮我解决这个问题吗?

这是我的 config.xml 文件

   <?xml version="1.0" encoding="UTF-8"?>
<widget xmlns   = "http://www.w3.org/ns/widgets"
        xmlns:gap   = "http://phonegap.com/ns/1.0"

        id        = "io.example.com"
        version     = "1.0.2">
    <name>MyAPP</name>

    <description>

    </description>

    <author  email="rakesh@gmail.com">
        Rakesh
    </author>

    <access origin="*"/>


    <content src="index.html" />


    <preference name="target-device" value="universal" />   <!-- all: possible values handset, tablet, or universal -->
    <!-- <preference name="fullscreen" value="true" />  -->          <!-- all: hides the status bar at the top of the screen -->
    <preference name="webviewbounce" value="false" />        <!-- ios: control whether the screen 'bounces' when scrolled beyond the top -->
    <preference name="ios-statusbarstyle" value="black-opaque" />   <!-- ios: black-translucent will appear black because the PhoneGap webview doesn't go beneath the status bar -->
    <preference name="auto-hide-splash-screen"    value="true" />           <!-- ios: if set to false, the splash screen must be hidden using a JavaScript API -->
    <preference name="android-minSdkVersion"      value="7" />              <!-- android: MIN SDK version supported on the target device. MAX version is blank by default. -->
    <preference name="phonegap-version" value="3.7.0" />
    <icon src="icon.png" />

    <icon src="icon-57.png"            gap:platform="ios"        width="57" height="57" />
    <icon src="icon-72.png"            gap:platform="ios"        width="72" height="72" />
    <icon src="icon-57-2x.png"         gap:platform="ios"        width="114" height="114" />
    <icon src="icon-72-2x.png"         gap:platform="ios"        width="144" height="144" />
    <icon src="icon-120.png"           gap:platform="ios"        width="120" height="120" />
    <icon src="icon-76.png"            gap:platform="ios"        width="76" height="76" />
    <icon src="icon-76-2x.png"         gap:platform="ios"        width="152" height="152" />

    <gap:plugin name="com.phonegap.plugin.statusbar" />
    <gap:plugin name="org.apache.cordova.device" />
    <gap:plugin name="org.apache.cordova.dialogs" />
    <gap:plugin name="org.apache.cordova.camera" />
    <gap:splash src="SplashScreenImage.jpg" gap:platform="winphone" />
    <gap:splash src="splash.png" />
    <gap:splash src="screen-iphone-portrait.png"         gap:platform="ios"     width="320" height="480" />
    <gap:splash src="screen-iphone-portrait-2x.png"      gap:platform="ios"     width="640" height="960" />
    <gap:splash src="screen-iphone-portrait-568h-2x.png" gap:platform="ios"     width="640" height="1136" />
    <gap:splash src="screen-ipad-portrait.png"           gap:platform="ios"     width="768" height="1024" />
    <gap:splash src="screen-ipad-landscape.png"          gap:platform="ios"     width="1024" height="768" />

    <gap:config-file platform="ios" parent="CFBundleShortVersionString">
    <string>100</string>
    </gap:config-file>

    <feature name="App">
      <param name="android-package" value="org.apache.cordova.App"/>
    </feature>
    <feature name="http://api.phonegap.com/1.0/network"/>

    <!-- Deprecated plugins element. Remove in 3.0 -->


</widget>

【问题讨论】:

  • 请分享您的 config.xml
  • 请分享一些代码内容,以便更好地了解您的错误。

标签: ios cordova phonegap-plugins ios-statusbar


【解决方案1】:

从 sunil 接受的答案不再相关,该插件已弃用。

在您的 config.xml 中使用以下内容

<preference name="StatusBarOverlaysWebView" value="false" />
<preference name="StatusBarBackgroundColor" value="#000000" />
<preference name="StatusBarStyle" value="lightcontent" />
<plugin spec="https://github.com/apache/cordova-plugin-statusbar.git" source="git" />

【讨论】:

  • 这创建了一个干净且间隔良好的状态栏,黑色背景和白色字体颜色将应用程序与状态栏分开。非常适合我的应用程序,谢谢~
  • 即使我按照您提到的方式进行操作,它也无法正常工作。
【解决方案2】:

将这些行添加到您的 config.xml 文件中

<preference name="StatusBarOverlaysWebView" value="false" />
        <preference name="StatusBarBackgroundColor" value="#000000" />
        <preference name="StatusBarStyle" value="lightcontent" />
      <gap:plugin name="com.phonegap.plugin.statusbar" />

【讨论】:

    【解决方案3】:

    这可以在statusbar plugin 的帮助下完成。 您只需通过命令行phonegap plugin add https://github.com/apache/cordova-plugin-statusbar.git 安装插件,然后添加StatusBar.hide(); onDeviceReady 事件。

    【讨论】:

    • 问题不是隐藏元素。它不应该与内容重叠。
    【解决方案4】:

    关于现在codova 6+的详细用法,更多@sunil的解决方案,我们应该使用

    cordova plugins add -save cordova-plugin-statusbar
    

    详细用法:https://www.npmjs.com/package/cordova-plugin-statusbar

    【讨论】:

      【解决方案5】:

      如果您想完全隐藏 StatusBar,您可以在 info.plist 中添加两个键,它们是布尔值:

      Status bar is initially hidden - YES
      
      View controller-based status bar appearance - NO
      

      【讨论】:

        【解决方案6】:

        应用@sunil 分辨率但是,

        我的问题是 iOS 10 上的“内容安全策略”

        在 index.html 中添加以下行解决了该问题:

        <meta http-equiv="Content-Security-Policy" content="default-src 'self' gap://ready file://* *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">
        

        【讨论】:

          【解决方案7】:

          config.xml 中添加这些行,使用它会解决您的问题并出现状态栏:

          <preference name="StatusBarOverlaysWebView" value="true"/>
          
          <preference name="StatusBarBackgroundColor" value="#000000"/>
          
          <preference name="StatusBarStyle" value="lightcontent" />
          

          【讨论】:

          • “这些行”是什么意思?
          • 这没有提供问题的答案。要批评或要求作者澄清,请在他们的帖子下方留下评论。 - From Review
          • 在混合应用程序中有一个配置文件,我们必须在其中输入一些条目以正确显示状态栏
          猜你喜欢
          • 2015-01-21
          • 1970-01-01
          • 1970-01-01
          • 2013-09-24
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-09-24
          • 1970-01-01
          相关资源
          最近更新 更多