离子3:后退按钮硬件事件处理程序无法确定覆盖视图

问题描述 投票:0回答:1

我有一个ionic 3应用程序,并且我修改了硬件后退按钮的功能。它可以在页面上运行,但无法确定是否存在模式视图和警报对话框之类的叠加视图。

这是我的代码

    this.platform.registerBackButtonAction(() => { 
      let nav = app._appRoot._getActivePortal() || app.getActiveNav();
      let activeView = nav.getActive().instance;

      if (activeView != null) {
        if (nav.canGoBack()) {
            if (activeView instanceof MultiRegistrationOne || activeView instanceof MultiRegistrationTwo || activeView instanceof MultiRegistrationThree) {
                // do something
            } else {
               nav.pop();
            }
        } else if (activeView.isOverlay) {
          activeView.dismiss();
        } else {
          let alert = this.alertCtrl.create({
            title: 'Ionic App',
            message: 'Do you want to close the app?',
            buttons: [{
              text: 'Cancel',
              role: 'cancel',
              handler: () => {
                console.log('Application exit prevented!');
              }
            },
            {
              text: 'Close',
              handler: () => {
                this.platform.exitApp();
              }
            }]
          });
          alert.present();
        }
      }
    });

我希望有人可以帮助我。预先谢谢😊

android ionic-framework ionic3 hybrid-mobile-app
1个回答
0
投票

声明一个变量:viewController:ViewController然后在页面或app.components.ts中,将后退按钮句柄修改为类似于

this.platform.registerBackButtonAction(() => {
  try{
    this.viewController.dismiss()

  }
  catch(e){
    console.log("error");
  }

});
© www.soinside.com 2019 - 2024. All rights reserved.