2015-01-07 60 views

回答

2

静态定位锁定

如果您正在使用PhoneGap Build,将它添加到您的config.xml中

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

如果没有,您需要修改配置为每个平台(清单。 xml,plist)分开包含此指令。

对于Android,添加

android:screenOrientation="landscape" 

的活动标签,这样

<activity android:name="MyActivity" 
    android:screenOrientation="landscape" 

对于iOS,加

UISupportedInterfaceOrientations 

与价值

UIInterfaceOrientationLandscapeLeft 

UIInterfaceOrientationLandscapeRight 

的plist

动态定向锁定

如果你不是想改变每次观看的方向,你可以使用Cordova plugin by yoik从你的JavaScript代码中动态调整的取向是这样

screen.lockOrientation("landscape"); 

与解锁

screen.unlockOrientation(); 
+0

我将它添加到config.xml,但是当我运行它删除automaticall y –

+0

我应该在哪里放置screent.lockOrientation(“风景”);? –

+0

高度依赖于您试图实现的目标。如果您只想将整个应用程序的方向锁定为横向,则应该使用提供的静态方法。如果您只想将某些视图锁定到横向,则应调用_screen.lockOrientation(“横向”); _当您想要锁定它时,例如在_deviceReady_事件上或想要锁定方向时。 –