离子取消硬BACK按钮覆盖 [英] Ionic cancel hard BACK button override

查看:148
本文介绍了离子取消硬BACK按钮覆盖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关于覆盖Ionic中物理Android BACK按钮的问题,以提供自定义行为:

There are questions about overriding the physical Android BACK button in Ionic, to provide custom behaviour:

  • Ionic override all BACK button behaviour for specific controller
  • Ionic: How to override back button function?

但是如何取消覆盖以恢复默认行为?

But how do you cancel the override to restore default behaviour?

我尝试更改处理程序的优先级,希望默认处理程序可能具有更高的优先级。

I have tried changing the priority of the handler, in the hope that a default handler may have a higher priority.

var customBackButton = function() {
    console.log("this is custom behaviour");
};
$ionicPlatform.registerBackButtonAction(
    customBackButton, 101
);
$scope.$on('$destroy', function() {
    $ionicPlatform.registerBackButtonAction(
        customBackButton, 0
    );
});

这不起作用。

推荐答案

离子v1解决方案(已过期)

根据 <$ c的Ionic docs $ c> $ ionicPlatform registerBackButtonAction()返回:


一个函数,当被调用时,将取消注释这个backButtonAction。

A function that, when called, will deregister this backButtonAction.

这可以在代码中看到for registerBackButtonAction()

This can be seen in the code for registerBackButtonAction():

  // return a function to de-register this back button action
  return function() {
    delete self.    [action.id];
  };






因此,取消注册/取消自定义的正确方法行为是在控制器被销毁时调用该函数:


So the correct way to deregister / cancel the custom behaviour is to call that function when the controller is destroyed:

var customBackButton = function() {
    console.log("this is custom behaviour");
};

// registerBackButtonAction() returns a function which can be used to deregister it
var deregisterBackButtonAction = $ionicPlatform.registerBackButtonAction(
    customBackButton, 101
);

$scope.$on('$destroy', function() {
    deregisterBackButtonAction();
});






一个更完整的例子,显示如何覆盖&恢复硬按钮和软按钮可以在这里找到:


A more complete example showing how to override & restore the hard and soft buttons can be found here:

  • Ionic override all BACK button behaviour for specific controller

这篇关于离子取消硬BACK按钮覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆