gpt4 book ai didi

ionic-framework - ionic 取消硬返回按钮覆盖

转载 作者:行者123 更新时间:2023-12-02 01:34:03 25 4
gpt4 key购买 nike

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

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

  • 但是你怎么做 取消覆盖 恢复默认行为?

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

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

    这不起作用。

    最佳答案

    Ionic v1 解决方案(过时)

    根据Ionic docs for $ionicPlatform , registerBackButtonAction()返回:

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



    这可以在 registerBackButtonAction() 的代码中看到。 :

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

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

    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();
    });

    一个更完整的例子展示了如何覆盖和恢复硬按钮和软按钮可以在这里找到:
  • Ionic override all BACK button behaviour for specific controller
  • 关于ionic-framework - ionic 取消硬返回按钮覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32245181/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com