[英]Why screen Orientation lock will not work
我正在嘗試將 ionic 4 應用程序中一頁的屏幕方向修復為縱向。
使用cordova插件: https : //github.com/apache/cordova-plugin-screen-orientation
記錄當前方向並監控方向的變化工作正常。 但是當我嘗試鎖定屏幕方向時,沒有任何反應,並且屏幕在方向改變時繼續旋轉。
當應用程序嘗試鎖定頁面時,我在 android studio 上收到以下錯誤消息:
2020-01-06 13:30:26.003 1913-2198/com.projectX E/Capacitor: Post message error:
java.lang.NullPointerException: Attempt to invoke virtual method 'void org.apache.cordova.CordovaPlugin.privateInitialize(java.lang.String, org.apache.cordova.CordovaInterface, org.apache.cordova.CordovaWebView, org.apache.cordova.CordovaPreferences)' on a null object reference
at org.apache.cordova.PluginManager.getPlugin(PluginManager.java:171)
at org.apache.cordova.PluginManager.exec(PluginManager.java:122)
at com.getcapacitor.MessageHandler.callCordovaPluginMethod(MessageHandler.java:70)
at com.getcapacitor.MessageHandler.postMessage(MessageHandler.java:46)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:326)
at android.os.Looper.loop(Looper.java:165)
at android.os.HandlerThread.run(HandlerThread.java:65)
下面是我的 app.module.ts
import { ScreenOrientation } from '@ionic-native/screen-orientation/ngx';
@NgModule({
providers: [
ScreenOrientation
],
})
下面是我想鎖定方向的頁面,map.page.ts
import { ScreenOrientation } from '@ionic-native/screen-orientation/ngx';
export class MapPage {
places: Place[];
@ViewChild(IonContent) content: IonContent;
constructor(public platform: Platform, public renderer: Renderer, private
alertCtrl: AlertController, private router: Router, private placeService:
PlaceService, public navCtrl: NavController, private screenOrientation:
ScreenOrientation) {
}
ngOnInit() {
console.log("lockorientation ");
screen.orientation.lock('portrait');
console.log("lockorientation ");
}
我還在使用 confix.xml 文件以縱向鎖定應用程序,使用:
<preference name="orientation" value="portrait" />
但應用程序只是忽略該命令並繼續旋轉。
在您的代碼中使用它
this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.PORTRAIT);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.