• ionic实现双击返回键退出软件


    1.首先要安装cordova插件:插件地址:cordova plugin add https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin.git

    2.在run.js中的代码:(注意参数要加上)

    .run(function ($ionicPlatform, $rootScope, $location, $timeout, $ionicHistory, $cordovaToast) {
            $ionicPlatform.ready(function ($rootScope) {
                // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
                // for form inputs)
                if (window.cordova && window.cordova.plugins.Keyboard) {
                    cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
                }
                if (window.StatusBar) {
                    // org.apache.cordova.statusbar required
                    StatusBar.styleDefault();
                }
            });
            //双击退出
            $ionicPlatform.registerBackButtonAction(function (e) {
                //判断处于哪个页面时双击退出
                if ($location.path() == '/main) {
                    if ($rootScope.backButtonPressedOnceToExit) {
                        ionic.Platform.exitApp();
                    } else {
                        $rootScope.backButtonPressedOnceToExit = true;
                        $cordovaToast.showShortTop('再按一次退出系统');
                        setTimeout(function () {
                            $rootScope.backButtonPressedOnceToExit = false;
                        }, 2000);
                    }
                }
                else if ($ionicHistory.backView()) {
                    $ionicHistory.goBack();
                } else {
                    $rootScope.backButtonPressedOnceToExit = true;
                    $cordovaToast.showShortTop('再按一次退出系统');
                    setTimeout(function () {
                        $rootScope.backButtonPressedOnceToExit = false;
                    }, 2000);
                }
                e.preventDefault();
                return false;
            }, 101);
        })
    但是不知道是为什么返回历史这一个没有实现,由于开发的软件页面也不是特别多,所以找到一下的解决方案:
    else if ($ionicHistory.currentStateName() == 'edit') {
    $state.go('main');
    }
    判断当前的state是否为edit,是的话返回首页面~
    参考文章:http://ionichina.com/topic/5514b539b6421f9166aa5f88
  • 相关阅读:
    如何搭建SVN的客户端和使用
    SVN服务器的本地搭建和使用
    grep命令
    cat命令
    cut命令
    yum 命令
    XPath、XQuery 以及 XSLT 函数
    XPath 实例
    XPath 运算符
    XPath Axes(轴)
  • 原文地址:https://www.cnblogs.com/maoyazhi/p/4377981.html
Copyright © 2020-2023  润新知