关于在 Ionic 中覆盖物理 Android BACK 按钮以提供自定义行为存在一些问题:
- Ionic 覆盖特定控制器的所有“后退”按钮行为
- Ionic:如何覆盖后退按钮功能?
但你如何取消覆盖恢复默认行为?
我尝试更改处理程序的优先级,希望默认处理程序可以具有更高的优先级。
var customBackButton = function() {
console.log("this is custom behaviour");
};
$ionicPlatform.registerBackButtonAction(
customBackButton, 101
);
$scope.$on('$destroy', function() {
$ionicPlatform.registerBackButtonAction(
customBackButton, 0
);
});
这是行不通的。
Ionic v1 解决方案(已过时)
根据离子文档$ionicPlatform, the registerBackButtonAction()
返回:
一个函数,在调用时将取消注册此 backButtonAction。
这可以在代码中看到registerBackButtonAction()
:
// return a function to de-register this back button action
return function() {
delete self. [action.id];
};
因此,注销/取消自定义行为的正确方法是在控制器被销毁时调用该函数:
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();
});
可以在此处找到显示如何覆盖和恢复硬按钮和软按钮的更完整示例:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)