繁体   English   中英

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

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

如何为Windows Store App获得彼此独立的缩放x和y缩放比例值? 我目前正在使用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:

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

代码大多取自此处

我最终在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