1

我目前正在使用以下代码来检测手势

var inputManager = (function () {
    var that = {};
    var gr;
    var canvas;
    var manipulating = false;


    that.manipulationHandler = function (evt) {
        if (evt.delta) {
            //
        }
    };

    that.isManipulating = function () {
        return manipulating;
    };

    that.processDown = function (evt) {
        gr.processDownEvent(evt.currentPoint);
    };

    that.processMove = function (evt) {
        gr.processMoveEvents(evt.intermediatePoints);
    };

    that.processUp = function (evt) {
        gr.processUpEvent(evt.currentPoint);
    };

    that.processMouse = function (evt) {
        gr.processMouseWheelEvent(evt.currentPoint, evt.shiftKey, evt.ctrlKey);
    };

    // The following functions are registered to handle GestureRecognizer gesture events
    that.manipulationStartedHandler = function (evt) {
        manipulating = true;
        that.manipulationHandler(evt);
    };

    that.manipulationDeltaHandler = function (evt) {
        that.manipulationHandler(evt);
    };

    that.manipulationEndHandler = function (evt) {
        manipulating = false;
        that.manipulationHandler(evt);
    };

    that.tappedHandler = function (evt) {
    };

    that.initialize = function () {

        gr = new Windows.UI.Input.GestureRecognizer();

        gr.gestureSettings =
            Windows.UI.Input.GestureSettings.manipulationRotate |
            Windows.UI.Input.GestureSettings.manipulationTranslateX |
            Windows.UI.Input.GestureSettings.manipulationTranslateY |
            Windows.UI.Input.GestureSettings.manipulationScale |
            Windows.UI.Input.GestureSettings.manipulationRotateInertia |
            Windows.UI.Input.GestureSettings.manipulationScaleInertia |
            Windows.UI.Input.GestureSettings.manipulationTranslateInertia |
            Windows.UI.Input.GestureSettings.tap;

        // Turn off UI feedback for gestures (we'll still see UI feedback for PointerPoints)
        gr.showGestureFeedback = true;

        // Register event listeners for the gestures that we just configured
        gr.addEventListener('manipulationstarted', that.manipulationStartedHandler);
        gr.addEventListener('manipulationupdated', that.manipulationDeltaHandler);
        gr.addEventListener('manipulationcompleted', that.manipulationEndHandler);
        gr.addEventListener('tapped', that.tappedHandler);

        canvas = document.getElementById("canvas");

        // Register event listeners for DOM pointer events, these are the
        // raw touch events we will be using to feed the gestureRecognizer
        canvas.addEventListener('MSPointerDown', that.processDown, false);
        canvas.addEventListener('MSPointerMove', that.processMove, false);
        canvas.addEventListener('MSPointerUp', that.processUp, false);
        canvas.addEventListener('MSPointerCancel', that.processUp, false);
        canvas.addEventListener('wheel', that.processMouse, false);
    };

    return that;
})();

但我得到了错误

0x80400000 - JavaScript 运行时错误:无法按非时间顺序处理输入数据。

WinRT 信息:无法按非时间顺序处理输入数据。

当您在设备上疯狂地轻敲时,在 processMove 函数中抛出。我使用的设备是多点触控平板电脑。在每个函数周围添加 try catch 块似乎可以解决它。

that.processDown = function (evt) {
        try { 
            gr.processDownEvent(evt.currentPoint);
        } catch (e) { }
    };

    that.processMove = function (evt) {

        try {
            gr.processMoveEvents(evt.intermediatePoints);

        } catch (e) { }
    };

    that.processUp = function (evt) {
        try {
            gr.processUpEvent(evt.currentPoint);
        } catch (e) { }
    };

这是检测多点触控设备上的手势和处理引发的错误的正确/最佳方法吗?

4

0 回答 0