【问题标题】:Ionic 3 - Screen Orientation Lock not workingIonic 3 - 屏幕方向锁定不起作用
【发布时间】:2018-01-19 03:53:32
【问题描述】:

我的要求是让应用程序仅在手机上固定为纵向模式,并且仅在选项卡上固定为横向模式,从启动画面开始。尝试使用 ionic native 上的 Screen Orientation 插件,但对我不起作用。

我尝试过的事情:

在 app.component.ts 上:

constructor(..., private screenOrientation: ScreenOrientation) {
    platform.ready().then(() => {

        this.screenOrientation.lock('landscape');
        ScreenOrientation.lockOrientation('landscape');
        screen.msLockOrientation('landscape');
    this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.LANDSCAPE);

我也在 home.ts 上尝试了上述所有行,但它们没有用。当我设置:

console.log(this.screenOrientation.type); 

这将在日志中正确打印出屏幕方向。每当我设置订阅方法时,它也会在屏幕方向发生变化时提醒我,这意味着所有导入语句都可以正常工作并且我能够正确访问插件方法。我能够在 Android 和 iOS 上复制这个问题。任何帮助将不胜感激。

平台/库/依赖项详细信息:

"@angular/common": "4.1.3",

“离子角度”:“3.6.0”,

“离子”:“3.7.0”

【问题讨论】:

    标签: angular ionic2 screen-orientation ionic3 ionic-native


    【解决方案1】:

    在您的config.xml 中,您可以尝试添加此行以使您的方向锁定为横向模式。

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

    【讨论】:

    • 这在我必须锁定所有设备的方向时有效。但是,我只需要为手机保持纵向,只为标签保持横向。
    【解决方案2】:

    最后一个选项应该可以工作。我使用它的方式如下:

    平板电脑:this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.LANDSCAPE);

    对于移动设备: this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.PORTRAIT);

    尝试移除 ScreenOrientation 模块,移除平台,然后重新添加平台,再次添加 ScreenOrientation 模块。它也可能是您正在调试的设备

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-29
      • 1970-01-01
      • 2022-10-24
      • 2015-10-12
      • 2014-01-13
      • 2019-08-29
      相关资源
      最近更新 更多