2017-08-10 86 views
2

我的要求是將應用程序僅固定在手機上的縱向模式,並且僅適用於選項卡上的橫向模式,從splashscreen開始。試圖與屏幕取向插件可用離子本土,但沒有爲我工作。Ionic 3 - 屏幕方向鎖定不起作用

事情我已經嘗試:

在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上覆制此問題。任何幫助將不勝感激。

平臺/庫/依賴性細節:

「@角/共同」: 「4.1.3」,

「離子 - 角」: 「3.6.0」,

「離子」:「3.7.0」

回答

0
在你的config.xml

你可以嘗試加入這行,讓您的方位鎖定在橫向模式。

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

這適用於我必須鎖定所有設備的方向。但是,我只需要保留它的肖像僅適用於手機,並且只適用於製表符。 –