如何限制应用程序只能在所有平台的离子肖像模式
我在Ionic / Cordova上工作,我把这个添加到了androidManifest.xml但是这对我不起作用,应用程序仍然显示在两个方面 
 android:screenOrientation="portrait" 
我怎么能限制我的应用程序只有肖像模式? 我检查了Android,它不工作
如果您只想在所有设备上限制为纵向模式,则应将此行添加到项目根文件夹中的config.xml中。
 <preference name="orientation" value="portrait" /> 
之后,请在命令行中input以下文本重build平台:
 ionic build 
离子v2 +更新
 对于Ionic版本2和更高版本,您还需要为您使用的任何插件安装相应的Ionic Native软件包,包括cordova-plugin-和phonegap-plugin- plugin phonegap-plugin- plugins。 
- 
安装Ionic本机插件 从CLI为插件安装Ionic Native的TypeScript模块。 $ ionic cordova plugin add --save cordova-plugin-screen-orientation $ npm install --save @ionic-native/screen-orientation*请注意,– --save命令是可选的,如果您不想将该插件添加到您的package.json文件
- 
导入 ScreenOrientation插件将插件导入到您的 controller, 文档中提供了更多详细信息。import { ScreenOrientation } from '@ionic-native/screen-orientation'; @Component({ templateUrl: 'app.html', providers: [ ScreenOrientation ] }) constructor(private screenOrientation: ScreenOrientation) { // Your code here... }
- 
做你的事 以编程方式locking和解锁屏幕方向。 // Set orientation to portrait this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.PORTRAIT); // Disable orientation lock this.screenOrientation.unlock();
- 
奖励积分 你也可以得到当前的方向。 // Get current orientation console.log(this.screenOrientation.type); // Will return landscape" or "portrait"
根据https://cordova.apache.org/docs/en/4.0.0/config_ref/#global-preferences ,
方向允许您locking方向,并防止接口因方向变化而旋转。 可能的值是默认,横向或纵向。 例:
 <preference name="Orientation" value="landscape" /> 
请注意,这些值是区分大小写的,它是“方向”,而不是“方向”。
 在你的angular app.js里面添加一行screen.lockOrientation('portrait'); 如下图所示: 
一个
 angular.module('app', ['ionic']) .run(function($ionicPlatform) { // LOCK ORIENTATION TO PORTRAIT. screen.lockOrientation('portrait'); }); }) 
 你在.run函数中也会有其他代码,但是你感兴趣的是我写的那一行。 我在代码中没有添加<preference name="orientation" value="portrait" /> ,但是您可能需要添加cordova-plugin-device-orientation 
首先,您需要使用Cordova Screen Orientation Plugin
 cordova plugin add cordova-plugin-screen-orientation 
 然后添加screen.lockOrientation('portrait'); 到.run()方法 
 angular.module('myApp', []) .run(function($ionicPlatform) { screen.lockOrientation('portrait'); console.log('Orientation is ' + screen.orientation); }); }) 
你可以试试这个:
Cordova插件以iOS,Android,WP8和Blackberry 10的通用方式设置/locking屏幕方向。该插件基于Screen Orientation API的早期版本,因此api当前不符合当前的规范。
 https://github.com/apache/cordova-plugin-screen-orientation 
或者在xml config中尝试下面的代码:
 <preference name="orientation" value="portrait" />