如何使用 Ionic Framework 将特定视图强制为横向

How can I force a specific view to be landscape using the Ionic Framework

我有一个应用程序在 config.xml 中强制纵向显示,但我希望应用程序中的特定视图显示为横向。实现这一目标的最佳方法是什么? Ionic Framework 中是否已有选项?

我已经尝试通过 CSS 将视图控制器设置为将页面容器元素旋转 90 度,但这是一个糟糕的 hack,因为 OS 不知道应该旋转设备并且因此状态 bar/OS 导航项不会旋转。

有没有办法在使用 Ionic Framework 时强制特定视图到指定方向?

看来 this 插件会对你有所帮助。

对于横向,您必须在控制器中使用 screen.lockOrientation('landscape');

而在其他页面上,如果它们不是纵向视图,则必须放置 screen.lockOrientation('portrait');

for Ionic 2.x 有ionic原生插件可以使用。

import { ScreenOrientation } from '@ionic-native/screen-orientation';

constructor(private screenOrientation: ScreenOrientation) { }

...


// get current
console.log(this.screenOrientation.type); // logs the current orientation, example: 'landscape'

// set to landscape
this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.LANDSCAPE);

// allow user rotate
this.screenOrientation.unlock();

// detect orientation changes
this.screenOrientation.onChange().subscribe(
   () => {
       console.log("Orientation Changed");
   }
);

参见 here