【问题标题】:PhoneGap - Preventing Screen Orientation ChangesPhoneGap - 防止屏幕方向更改
【发布时间】:2016-07-23 18:45:48
【问题描述】:

我使用了一个插件来尝试在我的 PhoneGap 应用中锁定屏幕方向:

cordova-plugin-screen-orientation

在我的应用页面中,我有以下代码摘录:

// Once DOM is loaded...
$(document).on('pagecreate', function() {

window.screen.lockOrientation('portrait');                  // Seems to set variable but not LOCK screen?

var orient = screen.orientation;                            // Works
alert(orient);                                              // Works

window.addEventListener("orientationchange", function(){    // Works
    alert(screen.orientation); // e.g. portrait             // Works
});                                      

... Other code etc.

正如您从 cmets 中看到的那样,插件似乎已正确安装,因为我在旋转手机时成功调用了纵向主、横向辅助等。问题似乎是该功能没有锁定屏幕?

任何帮助将不胜感激!

【问题讨论】:

  • 您想在整个应用中锁定方向吗?
  • @ShashankAgrawal - 是的,我希望锁定整个应用程序。根据下面的评论,我尝试通过 avi config.xml 文件执行此操作,但没有运气。

标签: android ios cordova phonegap-plugins phonegap-desktop-app


【解决方案1】:

尝试在您的config.xml 中设置此属性。

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

【讨论】:

  • 感谢您的回复。我实际上已经在 config.xml 中得到了它,但它仍然不会锁定方向。这可能与运行 PhoneGap 桌面和 iOS 应用程序而不是进行完整的“构建”有关吗?我之前没有构建过应用程序,因此它可能是 PhoneGap 环境的细微差别。
猜你喜欢
  • 1970-01-01
  • 2016-02-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多