首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >针对将在Android/iOS上运行的离子/电容器应用的离子5锁屏幕方向

针对将在Android/iOS上运行的离子/电容器应用的离子5锁屏幕方向
EN

Stack Overflow用户
提问于 2021-09-18 18:06:52
回答 1查看 311关注 0票数 1

我正在尝试弄清楚如何锁定整个应用程序的屏幕方向,这样当它部署到Android/iOS时,它只在其纵向模式下使用。

我看到相当多的问题被问和回答使用科尔多瓦和config.xml。但我使用的是电容,所以它不同于我没有config.xml文件。相反,我有一个ionic.config.json文件。

这就是我到目前为止在app.module.tsapp.component.ts中所拥有的

代码语言:javascript
代码运行次数:0
运行
复制
    import { NgModule } from '@angular/core';
    import { BrowserModule } from '@angular/platform-browser';
    import { RouteReuseStrategy } from '@angular/router';
    
    import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
    
    import { AppComponent } from './app.component';
    import { AppRoutingModule } from './app-routing.module';
    import {ScreenOrientation} from "@ionic-native/screen-orientation/ngx";
    
    
    @NgModule({
      declarations: [AppComponent],
      entryComponents: [],
      imports: [BrowserModule, IonicModule.forRoot(), AppRoutingModule],
      providers: [{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy }, ScreenOrientation],
      bootstrap: [AppComponent],
    })
    export class AppModule {
      constructor() {
    
      }
    
    }

代码语言:javascript
代码运行次数:0
运行
复制
export class AppComponent {
  constructor(private screenOrientation: ScreenOrientation) {
    this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.PORTRAIT);
  }

}

但我不相信这会在整个应用程序中锁定我的screenOrientation。我试着看过Ionic文档,但它是如此的赤裸裸。

EN

回答 1

Stack Overflow用户

发布于 2021-09-23 14:46:40

您需要将orientation参数传递给screenOrientation.lock方法

如下所示:

代码语言:javascript
代码运行次数:0
运行
复制
export class AppComponent {
  constructor(private screenOrientation: ScreenOrientation) {
    this.screenOrientation.lock('portrait');
  }
}

引用自:https://github.com/apache/cordova-plugin-screen-orientation

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69237241

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档