【问题标题】:How can I force a specific view to be landscape using the Ionic Framework如何使用 Ionic 框架强制特定视图为横向
【发布时间】:2016-05-30 15:03:46
【问题描述】:

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

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

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

【问题讨论】:

  • 好问题。但是,据我所知,这在 Ionic 框架中是不可能的,但如果有人知道解决方案,请纠正我。

标签: mobile ionic-framework orientation


【解决方案1】:

似乎this 插件会帮助你。

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

在其他页面上,如果它们不是纵向视图,您必须输入screen.lockOrientation('portrait');

【讨论】:

    【解决方案2】:

    对于 Ionic 2.x,可以使用离子原生插件。

    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。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多