문제

I've been using this article (and some others) to try and implement a gesture recognition in my app, and it does work. However, what I want to do is to detect multiple gestures; for example, a swipe, and a touch. What i don't seem to be able to do is to establish whether the MouseUp event is caused by the end of a gesture, or by a single touch.

function processUpEvent(e) {
    lastElement = e.currentTarget;
    gestureRecognizer.processUpEvent(e.currentPoint);

    processTouchEvent(e.currentPoint);
}

What happens currently is it processed both. How can I detect whether the user has 'let go' of the screen for a swipe, or a touch?

EDIT:

    var recognizer = new Windows.UI.Input.GestureRecognizer();        

    recognizer.gestureSettings = Windows.UI.Input.GestureSettings.manipulationTranslateX
    recognizer.addEventListener('manipulationcompleted', function (e) {
        var dx = e.cumulative.translation.x
        //Do something with direction here
    });

    var processUp = function (args) {
        try {
            recognizer.processUpEvent(args.currentPoint);
        }
        catch (e) { }
    }

    canvas.addEventListener('MSPointerDown', function (args) {
        try {
            recognizer.processDownEvent(args.currentPoint);
        }
        catch (e) { }
    }, false);

    canvas.addEventListener('MSPointerMove', function (args) {
        try {
            recognizer.processMoveEvents(args.intermediatePoints);
        }
        catch (e) { } 
    }, false);
    canvas.addEventListener('MSPointerUp', processUp, false);
    canvas.addEventListener('MSPointerCancel', processUp, false);

So I need to handle both processUp and manipulationcompleted, but one or the other.

도움이 되었습니까?

해결책 2

I've found a way to do this, but it's not pretty:

var eventFlag = 0;

var processUp = function (args) {
    try {
        recognizer.processUpEvent(args.currentPoint);

        if (eventFlag == 0) {
           // do stuff
        } else {
           eventFlag = 0;
        }
    }
    catch (e) { }
}

recognizer.gestureSettings = Windows.UI.Input.GestureSettings.manipulationTranslateX
recognizer.addEventListener('manipulationcompleted', function (e) {
    var dx = e.cumulative.translation.x
    //Do something with direction here
    eventFlag = 1;
});

다른 팁

You can have a look at my "input" demo in codeSHOW. Just install the codeSHOW app (http://aka.ms/codeshowapp) and look at the Pointer Input demo and "see the code" or just go to the source code on CodePlex. Hope that helps.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top