2013-05-02 62 views
3

我一直在使用this文章(以及其他人)尝试在我的应用中实现手势识别,并且它确实有效。但是,我想要做的是检测多个手势;例如,轻扫和触摸。我似乎无法做到的事情是确定MouseUp事件是由手势结束还是通过单键触发引起的。WinJS gestureRecognizer - 如何捕捉多个手势

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

    processTouchEvent(e.currentPoint); 
} 

当前发生的是它处理两个。如何检测用户是否放弃了屏幕刷卡或触摸?

编辑:

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

所以,我需要同时处理processUpmanipulationcompleted,但一个或另一个。

回答

1

我已经找到一种方法来做到这一点,但它不漂亮:

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

你可以看看我在codeSHOW中的“输入”演示。只需安装codeSHOW应用程序(http://aka.ms/codeshowapp)并查看指针输入演示和“查看代码”,或者转至source code on CodePlex。 希望有所帮助。

+0

我不知道这个回答我的问题。虽然这确实包括拖动,但我需要捕捉方向。我已经用一些更具体的细节更新了我的问题。 – 2013-05-04 10:00:48