我正在尝试弄清楚如何锁定整个应用程序的屏幕方向,这样当它部署到Android/iOS时,它只在其纵向模式下使用。
我看到相当多的问题被问和回答使用科尔多瓦和config.xml。但我使用的是电容,所以它不同于我没有config.xml文件。相反,我有一个ionic.config.json
文件。
这就是我到目前为止在app.module.ts
和app.component.ts
中所拥有的
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() {
}
}
和
export class AppComponent {
constructor(private screenOrientation: ScreenOrientation) {
this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.PORTRAIT);
}
}
但我不相信这会在整个应用程序中锁定我的screenOrientation。我试着看过Ionic文档,但它是如此的赤裸裸。
发布于 2021-09-23 06:46:40
您需要将orientation参数传递给screenOrientation.lock方法
如下所示:
export class AppComponent {
constructor(private screenOrientation: ScreenOrientation) {
this.screenOrientation.lock('portrait');
}
}
引用自:https://github.com/apache/cordova-plugin-screen-orientation
https://stackoverflow.com/questions/69237241
复制相似问题