我使用了一个插件来尝试在我的 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.
正如您从评论中看到的那样,插件似乎已正确安装,因为我在旋转手机时成功地调用了肖像为主、风景为辅等。问题似乎是该功能未锁定屏幕?
如有任何帮助,我们将不胜感激!
最佳答案
尝试在您的 config.xml
中设置此属性。
<preference name="Orientation" value="portrait" />
关于android - PhoneGap - 防止屏幕方向改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38545303/