2013-12-08 18 views
0

我有這個在我的XAML:WP8工具包GestureListener捏手勢 - 進還是出?

<toolkit:GestureService.GestureListener> 
    <toolkit:GestureListener PinchCompleted="GestureListener_PinchCompleted"/> 
</toolkit:GestureService.GestureListener> 

正如你所看到的,它創建時完成捏了事件處理程序。我有這個在我的代碼:

private void GestureListener_PinchCompleted(object sender, PinchGestureEventArgs e) 
{ 
    //how do I determine whether it was a pinch in or pinch out gesture? 
} 

當這個事件觸發,我想知道手勢是否合攏或掐出(即我們是否分別縮小或放大)。

這一切我都可以訪問:

e.DistanceRatio 
e.Handled 
e.OriginalSource 
e.TotalAngleDelta 

我只需要知道用戶是否要「放大」或縮小 - 我可以處理的動畫和一切。

回答

0

忘記發佈此更早。距離比率並不正確,因爲它並不總是正確的。我做了這個,而不是:

private void GestureListener_PinchStarted(object sender, PinchStartedGestureEventArgs e) 
{ 
    initialDistance = e.Distance; 
} 

private void GestureListener_PinchCompleted(object sender, PinchGestureEventArgs e) 
{ 
    double distance2 = e.DistanceRatio * initialDistance; 

    if (initialDistance > distance2) 
    { 
     //zoom out 
    } 
    else if (initialDistance < distance2) 
    { 
     //zoom in 
    } 
} 
0
PinchStarted="OnPinchStarted" add event in XAML 


private void OnPinchStarted(object sender, PinchStartedGestureEventArgs e) 
{ 

} 

檢測捏開始的第一座標和

private void GestureListener_PinchCompleted(object sender, PinchGestureEventArgs e) 
{ 

} 

嘗試確定。我想答案是,如果你不能訪問座標,然後在e.DistanceRatio

我認爲e.DistanceRatio - 將返回手指之間的距離。

所以,如果OnPinchStart它爲2cm和PinchEnd它爲1cm =放大

+0

雖然距離不能確定是捏合還是捏出。我的手指可以是相同的距離,無論我做了捏或捏。: –

0

的e.DistanceRatio確定DistanceBetweenFingersAfter/DistanceBetweenFingersBefore。因此,使它

if(e.DistanceRatio > 1){ 
//Zoom in 
} else { 
// Zoom out 
} 
+0

如何顯示更多的代碼 – tinybyte

+0

不知道還有什麼要補充,對不起m8。 – Jakkes