欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

三步實(shí)現(xiàn)ionic3點(diǎn)擊退出app程序

 更新時(shí)間:2019年09月17日 11:30:38   作者:changzhengcome  
這篇文章主要為大家詳細(xì)介紹了三步實(shí)現(xiàn)ionic3點(diǎn)擊退出app程序,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了ionic3點(diǎn)擊退出app程序的具體代碼,供大家參考,具體內(nèi)容如下

其實(shí)也很簡單。大概分為三步

1.tabs.ts文件需要聲明一下

@ViewChild('mainTabs') tabs:Tabs;//聲明tabs組件(<ion-tabs #mainTabs >)

2.app.component.ts文件

@ViewChild('myNav') nav: Nav;//聲明根組件(<ion-nav #myNav [root]="rootPage">)

3.貼代碼  

platform.ready().then(()=>{
this.exitApp();
})
public backButtonPressed: boolean = false;
exitApp() {
  this.platform.registerBackButtonAction(() => {
   //控制modal、系統(tǒng)自帶提示框
   let overlay = this.appCtrl._appRoot._overlayPortal.getActive() ||  this.appCtrl._appRoot._modalPortal.getActive();
   if (overlay) {
    overlay.dismiss();
    return;
   }
   let activeVC = this.nav.getActive();
   let page = activeVC.instance;
   if (page.tabs) {
    let activeNav = page.tabs.getSelected();
    if (activeNav.canGoBack()) {
     return activeNav.pop();
    } else {
     return this.showExit();
    }
   }
   if (page instanceof LoginPage) {//查看當(dāng)前頁面是否是登陸頁面
    this.showExit();
    return;
   }
   this.appCtrl.getActiveNav().pop();//剩余的情況全部使用全局路由進(jìn)行操作 
  });
 }
 
 //雙擊退出函數(shù)
 showExit() {
  if (this.backButtonPressed) {
   this.platform.exitApp();
  } else {
   this.presentToast();//再按一次退出
   this.backButtonPressed = true;
   setTimeout(() => {
    this.backButtonPressed = false;
   }, 2000)
  }
 }
 presentToast() {
  let toast = this.toastCtrl.create({
   message: '再按一次退出應(yīng)用',
   duration: 2000,
   position: 'top'
  });
 
  toast.onDidDismiss(() => {
   console.log('Dismissed toast');
  });
 
  toast.present();
 }

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論