【问题标题】:set orientation not locking to portrait [duplicate]将方向设置为不锁定为纵向[重复]
【发布时间】:2014-07-10 12:29:08
【问题描述】:

我正在使用 Cordova 和英特尔应用程序框架构建一个移动应用程序。我尝试将方向设置为纵向模式

var onDeviceReady = function () {        
    intel.xdk.device.setRotateOrientation('portrait');
    intel.xdk.device.setAutoRotate(false);
    intel.xdk.device.hideSplashScreen();

};
document.addEventListener("intel.xdk.device.ready", onDeviceReady, false);`

但是当我通过在 Android 4.4 中安装 APK 来检查构建时,它不起作用。它总是在两种模式下旋转。 有什么建议吗?

【问题讨论】:

    标签: cordova appframework


    【解决方案1】:

    如果您使用的是 Cordova/PhoneGap,您需要在 app 文件夹或 www 文件夹中的 config.xml 文件中将 Orientation 更改为“portrait”(通常为“default”)。 <preference name="Orientation" value="portrait" />

    PhoneGap 开发者应用并未反映此更改,因此您可以通过构建应用并运行它来进行测试。

    【讨论】:

      【解决方案2】:

      将此添加到您的 config.xml:

      <preference name="Orientation" value="portrait" />
      

      这适用于所有设备。

      【讨论】:

        【解决方案3】:

        好吧,我问了几乎相同的问题并尝试了我能找到的一切,甚至是这个问题的答案,但它对我不起作用,但我找到了一种方法:

        我最终使用了this(GitHub 链接)插件。

        该插件名为 cordova-yoik-screenorientation,您只需:

        下载 GitHub 存档。

        plugin.xmlsrc 文件夹复制到您的根文件。

        复制 screenorientation.android.jsscreenorientation.bb10.jsscreenorientation.ios.jsscreenorientation.js 到您的 www 文件夹。

        将以下内容添加到您的 index.html 头部

        <script>
           screen.lockOrientation('landscape');
        </script>
        

        ...您可以根据需要将 landscape 更改为 portrait

        【讨论】:

        • 太棒了!该插件适用于 iOS 8.1 和 8.3 :) 谢谢!
        • @nikolaygeorgiev 很高兴我能帮上忙 :)
        【解决方案4】:

        这种风格有效!

            <style>
                /* Landscape layout (with min-width) */
                @media screen and (min-aspect-ratio: 1/1) and (min-width:400px) {
                    .app {
                        background-position:left center;
                        padding:75px 0px 75px 170px;  /* padding-top + padding-bottom + text area = image height */
                        margin:-90px 0px 0px -198px;  /* offset vertical: half of image height */
                                                      /* offset horizontal: half of image width and text area width */
                    }
                }
            </style>
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多