cordova - 如何禁用ios的方向颠倒?

问题描述 投票:5回答:4

在我的应用程序(ionic + cordova)中,我为纵向设置了方向,但是当我打开xcode进行构建时,选项updside down是启用的。如何在config.xml中禁用颠倒?

我的config.xml

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

谢谢

ios cordova ionic-framework orientation
4个回答
1
投票

尝试将config.xml更改为:<preference name="orientation" value="default" />

然后在iOS的平台级别通过以下方式将您的偏好值更改为“portrait”:<preference name="orientation" value="default" />

Config Ref

默认值:默认值

允许值:默认值,横向,纵向。

这允许您锁定方向并防止界面响应方向的变化而旋转。

注意:默认值表示Cordova将从平台的清单/配置文件中删除方向首选项条目,从而允许平台回退到其默认行为。对于iOS,要指定纵向和横向模式,您将使用平台特定值“all”。

我遇到了相反的问题然后通过改变它来解决它。我希望这有帮助!


0
投票

你不能通过配置文件解开iOS“up-side-down”。

但您可以使用屏幕方向插件来控制它。 (website


0
投票

我找到了一个适用于我的项目的解决方案。使用已安装的Cordova插件cordova-custom-config,您可以使用UISupportedInterfaceOrientations中的以下代码覆盖<platform name="ios">-Setting:

<custom-config-file mode="replace" parent="UISupportedInterfaceOrientations" platform="ios" target="*-Info.plist">
    <array>
        <string>UIInterfaceOrientationPortrait</string>
    </array>
</custom-config-file>

重要的是参数mode="replace" Key的类型为Array,默认情况下将合并。

在平台标签之外,您可以设置默认的<preference name="orientation" value="portrait" />。这将用于Android和woont允许颠倒。


0
投票

唯一更好的方法是,在项目中安装cordova-plugin-screen-orientation插件。在ionic.Platform.ready(function() {})中使用以下代码:

if (window.cordova && cordova.plugins) {
    cordova.plugins.screenorientation.setOrientation('portrait-primary');
}

我也有同样的问题,这导致iPhone SE改变方向颠倒,这段代码为我修复了它。

© www.soinside.com 2019 - 2024. All rights reserved.