[英]Ionic/cordova Screen orientation not working
I've been developing an ionic app and it requires all but one screen to be locked in portrait mode. 我一直在开发一个离子应用程序,它只需要一个屏幕锁定在纵向模式。 So I added the screen orienation plugin via 所以我通过添加了屏幕定向插件
cordova plugin add cordova-plugin-screen-orientation
Then I added the supposedly simple line of code 然后我添加了所谓的简单代码行
window.screen.lockOrientation('portrait');
//does not work //不起作用
tried this aswell screen.lockOrientation('portrait');
尝试了这个以及screen.lockOrientation('portrait');
//does not work //不起作用
$ionicPlatform.ready(function() {
screen.lockOrientation('landscape');
});
with $ionicPlatform dependency included //does not work 包含$ ionicPlatform依赖项 //不起作用
Seems pretty straight forward but nothing is working 看起来很直接,但没有任何工作
Any help would be greatly appreciated..Thanks :) 任何帮助将不胜感激。谢谢:)
You can reliably lock the orientation of the screen in the config files of your cordova project. 您可以在cordova项目的配置文件中可靠地锁定屏幕的方向。 Just use 只是用
<preference name="Orientation" value="landscape" />
If you want to be more flexible and change it dependant to the current view. 如果您想要更灵活并根据当前视图更改它。 Go in the config files and add an orientation : 'portrait' attribute to the respective views. 进入配置文件并为相应的视图添加方向:'portrait'属性。 Afterwards simply declare: 之后简单地声明:
if(toState.orientation == 'portrait') {
screen.lockOrientation('portrait');
}
If that still doesn't work, try an implementation with another plugin. 如果仍然无效,请尝试使用其他插件实现。 This seems to be a fair altervative with a slightly different approach: https://github.com/Adlotto/cordova-plugin-recheck-screen-orientation 这似乎是一个公平的变化,采用略有不同的方法: https : //github.com/Adlotto/cordova-plugin-recheck-screen-orientation
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.