Я разрабатываю app, но в момент открытия ее он не обнаруживает меня, в котором ориентация находится и помещает мне три кнопки, которые у меня есть внизу с классами как будто они были ladscape, у меня есть метод, который предполагает, что он должен обнаруживать ее, и я это называю, но ничто не происходит, это мой код:
import { ScreenOrientation } from '@ionic-native/screen-orientation/ngx';
import { EventoDespacho } from './../../models/evento-despacho';
import { Component, OnInit } from '@angular/core';
import { StatusBarStyleService } from '../../utils/status-bar-style.service';
import { StatusBar } from '@ionic-native/status-bar/ngx';
import { Platform } from '@ionic/angular';
import { Subscription } from 'rxjs';
import { DespachoService } from 'src/app/api/despacho.service';
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss']
})
export class HomePage implements OnInit {
isVertical: boolean;
ngClasses: any;
ngClassesButtonsCont: any;
ngClassesButton: any;
ngClassesSlider: any;
imgServicios: string;
imgTramites: string;
imgLimpia: string;
staticThis = this;
backButtonSubscription: Subscription;
titulo = 'Servicios Capital';
constructor(
private statusBarStyle: StatusBarStyleService,
private statusBar: StatusBar,
private platform: Platform,
private screenOrientation: ScreenOrientation
) {}
ngOnInit(): void {
console.log('Home ngOnInit');
}
ionViewDidLoad() {
this.addEventListeners();
this.statusBarStyle.setDarkStatusBar(this.statusBar);
this.isVertical = true;
this.ngClasses = {};
this.ngClassesButtonsCont = {};
this.ngClassesButton = {};
this.ngClassesSlider = {};
this.imgServicios = '';
this.imgTramites = '';
this.imgLimpia = '';
this.onOrientationChange(null);
}
ionViewDidLeave() {
this.removeEventListeners();
}
/**
* Atiende el evento cuando se presiona el backbutton del dispositivo.
*/
onBackButtonClick() {
navigator['app'].exitApp();
}
/**
* Agrega los listeners de esta página.
*/
addEventListeners() {
window.addEventListener('orientationchange', this.onOrientationChange);
this.backButtonSubscription = this.platform.backButton.subscribe(
this.onBackButtonClick
);
}
/**
* Remueve los listeners que pertenecen a esta página para evitar duplicidad.
*/
removeEventListeners() {
window.removeEventListener('orientationchange', this.onOrientationChange);
this.backButtonSubscription.unsubscribe();
}
/**
* Realiza cambios en íconos y clases de la pantalla al girar la pantalla.
*/
onOrientationChange = event => {
const orientation = screen.orientation.type.toString();
this.isVertical = orientation.indexOf('portrait') >= 0;
this.ngClasses = {
'flex-c-col': this.isVertical,
'flex-container-row': !this.isVertical
};
this.ngClassesButtonsCont = {
'flex-container-row h-100': this.isVertical,
'flex-c-col m-l-10': !this.isVertical
};
this.ngClassesButton = {
'h-100': this.isVertical
};
this.ngClassesSlider = {
'mw-50': !this.isVertical
};
if (this.isVertical) {
this.imgServicios = '../../assets/images/BotonServiciosVertical.png';
this.imgTramites = '../../assets/images/BotonTramitesVertical.png';
this.imgLimpia = '../../assets/images/BotonLimpiaVertical.png';
} else {
this.imgServicios = '../../assets/images/BotonServicios.png';
this.imgTramites = '../../assets/images/BotonTramites.png';
this.imgLimpia = '../../assets/images/BotonLimpia.png';
}
}
}
Уже я старался "блокировать" ориентацию с this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.PORTRAIT_PRIMARY);
но это также не функционировало. Вещь, которую я заметил, состоит в том, что события ngOnInit и ionViewDidLoad они не названы, в момент которого вид загружается, когда я открываю приложение, и чтобы заставлять их функционировать я должен входить в другой вид и возвращать меня в первую и там он, когда уже он обнаруживает изменение и налаживает мне стили, в которые он, должно быть: больше он переместил кого-то это, что может помогать мне? Ах и также одинокое происходит со мной в iOS, android функционируй обычно, но у меня нет идеи почему.
Ты должен менять ее configuraciГіn в config.xml, aГ±adiendo tag especГ-fico для нее orientaciГіn в устройствах mГіviles. Я не помню, что cuГЎl - tag especГ-fico, но это encontrarГЎs fГЎcilmente. Я utilicГ© он делает какие-то aГ±os и это solucionГі проблема