)

2.app.component.ts文件

@ViewChild('myNav')nav:Nav;//声明根组件()

3.贴代码

platform.ready().then(()=>{
this.exitApp();
})
publicbackButtonPressed:boolean=false;
exitApp(){
this.platform.registerBackButtonAction(()=>{
//控制modal、系统自带提示框
letoverlay=this.appCtrl._appRoot._overlayPortal.getActive()||this.appCtrl._appRoot._modalPortal.getActive();
if(overlay){
overlay.dismiss();
return;
}
letactiveVC=this.nav.getActive();
letpage=activeVC.instance;
if(page.tabs){
letactiveNav=page.tabs.getSelected();
if(activeNav.canGoBack()){
returnactiveNav.pop();
}else{
returnthis.showExit();
}
}
if(pageinstanceofLoginPage){//查看当前页面是否是登陆页面
this.showExit();
return;
}
this.appCtrl.getActiveNav().pop();//剩余的情况全部使用全局路由进行操作
});
}

//双击退出函数
showExit(){
if(this.backButtonPressed){
this.platform.exitApp();
}else{
this.presentToast();//再按一次退出
this.backButtonPressed=true;
setTimeout(()=>{
this.backButtonPressed=false;
},2000)
}
}
presentToast(){
lettoast=this.toastCtrl.create({
message:'再按一次退出应用',
duration:2000,
position:'top'
});

toast.onDidDismiss(()=>{
console.log('Dismissedtoast');
});

toast.present();
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。

热门推荐

1 媳妇生日祝福语简短的
2 大学新年祝福语简短创意
3 牛年祝福语简短精辟搞笑
4 涂老师毕业祝福语简短
5 老师祝福语大全简短语
6 事业祝福语简短工作
7 同事调离的祝福语简短
8 新年祝福语送给妈妈简短
9 鸡年生男孩祝福语简短
10 广西考试祝福语结婚简短
11 猪年祝福语简短小孩
12 元旦祝福语送长辈简短
13 恭喜二宝祝福语简短
14 祝福语暖心话简短
15 国庆中秋祝福语简短兄弟
16 朋友订婚的祝福语简短
17 送弟弟中秋祝福语简短
18 爱生日祝福语简短独特