简体   繁体   English

在Windows Store Apps中获取彼此独立的缩放X / y缩放比例值

[英]Getting pinch-to-zoom x/y scale values independent of each other in Windows Store Apps

How do I get the pinch-to-zoom x and y scaling values independent of each other for a Windows Store App? 如何为Windows Store App获得彼此独立的缩放x和y缩放比例值? I'm currently using ManipulationDeltaRoutedEventArgs 's ManipulationDelta structure, but as you can see it only offers a single scale. 我目前正在使用ManipulationDeltaRoutedEventArgsManipulationDelta结构,但是如您所见,它仅提供一个比例。

// Global Transform used to change the position of the Rectangle.
private TranslateTransform dragTranslation;
private ScaleTransform scaleTransform;

// Constructor
public MainPage()
{
    InitializeComponent();

    // Add handler for the ManipulationDelta event
    TestRectangle.ManipulationDelta += Drag_ManipulationDelta;
    dragTranslation = new TranslateTransform();
    scaleTransform = new ScaleTransform();
    TestRectangle.RenderTransform = this.dragTranslation;
}

void Drag_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
    // Move the rectangle.
    dragTranslation.X += e.Delta.Translation.X;
    dragTranslation.Y += e.Delta.Translation.Y;

    // Scaling, but I want X and Y independent!
    scaleTransform.ScaleX = e.Delta.Scale;
    scaleTransform.ScaleY = e.Delta.Scale;
}

XAML: XAML:

<Rectangle Name="TestRectangle"
  Width="200" Height="200" Fill="Blue" 
  ManipulationMode="All"/>

Code mostly taken from here . 代码大多取自此处

I ended up using Handling Two, Three, Four Fingers Swipe Gestures in WinRT App to grab the coordinates of the two fingers, calculated the initial difference between them, and then scaled accordingly as the distance changed. 我最终在WinRT App中使用“ 处理两个,三个,四个手指滑动手势”来获取两个手指的坐标,计算它们之间的初始差值,然后根据距离的变化进行相应缩放。

int numActiveContacts;
Dictionary<uint, int> contacts;
List<PointF> locationsOfSortedTouches;

void myCanvas_PointerPressed(object sender, PointerRoutedEventArgs e) {
  PointerPoint pt = e.GetCurrentPoint(myCanvas);
  locationsOfSortedTouches.Add(new PointF((float) pt.Position.X, (float) pt.Position.Y));
  touchHandler.TouchesBegan(locationsOfSortedTouches);
  contacts[pt.PointerId] = numActiveContacts;
  ++numActiveContacts;
  e.Handled = true;
}

void myCanvas_PointerMoved(object sender, PointerRoutedEventArgs e) {
  var pt = e.GetCurrentPoint(myCanvas);
  var ptrId = pt.PointerId;
  if (contacts.ContainsKey(ptrId)) {
    var ptrOrdinal = contacts[ptrId];
    Windows.Foundation.Point currentContact = pt.Position;
    locationsOfSortedTouches[ptrOrdinal] = new PointF((float) pt.Position.X, (float) pt.Position.Y);
    //distance calculation and zoom redraw here
  }
  e.Handled = true;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM