I have this in my XAML:
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener PinchCompleted="GestureListener_PinchCompleted"/>
</toolkit:GestureService.GestureListener>
As you can see, it creates an event handler for when a pinch is completed. I have this in my code:
private void GestureListener_PinchCompleted(object sender, PinchGestureEventArgs e)
{
//how do I determine whether it was a pinch in or pinch out gesture?
}
When this event fires, I want to know whether the gesture was pinch in or pinch out (ie, whether we are zooming out or zooming in, respectively).
This is everything I can access:
e.DistanceRatio
e.Handled
e.OriginalSource
e.TotalAngleDelta
I just need to know whether the user wants to "zoom" in or out - I can handle the animations and everything else.
PinchStarted="OnPinchStarted" add event in XAML
private void OnPinchStarted(object sender, PinchStartedGestureEventArgs e)
{
}
Detect first coordinates of Pinch start and in
private void GestureListener_PinchCompleted(object sender, PinchGestureEventArgs e)
{
}
Try to determine. I think the answer will be if you cannot access the coordinates, then in e.DistanceRatio
I think that e.DistanceRatio - will return distance between fingers.
So if OnPinchStart it was 2 cm and on PinchEnd it is 1cm = Zoom In
The e.DistanceRatio determines the DistanceBetweenFingersAfter / DistanceBetweenFingersBefore. Thus making it
if(e.DistanceRatio > 1){
//Zoom in
} else {
// Zoom out
}
Forgot to post this earlier. The Distance Ratio doesn't exactly work, because it's not always correct. I did this instead:
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
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.