我有一个无法解决的问题。缩放和旋转工作正常,但是当旋转角度大于60度时,它将无法正常工作。这是视频link的工作原理。
这是计算代码,我使用了this教程进行计算。
private void Right(object sender, ManipulationDeltaRoutedEventArgs e, object a = null)
{
double distance = 0;
if (a != null)
{
CalculateLastPoint();
var posX = e.Container.TransformToVisual(canvas).TransformPoint(e.Position).X;
if ((int)a == 1)
{
distance = LastPointUpperRight.X - posX;
}
else
{
distance = LastPointRightBottom.X - posX;
}
}
else
{
distance = -e.Delta.Translation.X / Math.Cos(Radian);
}
if (Rec.Width - distance >= Rec.MinWidth)
{
Canvas.SetTop(this.Rec, Canvas.GetTop(this.Rec) - 0.5 * distance * Math.Sin(this.Radian));
Canvas.SetLeft(this.Rec, Canvas.GetLeft(this.Rec) + (distance * 0.5 * (1 - Math.Cos(this.Radian))));
this.Rec.Width -= distance;
}
} private void Top(object sender, ManipulationDeltaRoutedEventArgs e, object a = null)
{
double distance = 0;
if (a != null)
{
CalculateLastPoint();
var posX = e.Container.TransformToVisual(canvas).TransformPoint(e.Position).Y;
if ((int)a == 1)
{
distance = posX - LastPointUpperLeft.Y;
}
else
{
distance = posX - LastPointUpperRight.Y;
}
}
else
{
distance = e.Delta.Translation.Y / Math.Cos(Radian);
}
if (Rec.Height - distance >= Rec.MinHeight)
{
Canvas.SetTop(this.Rec,
Canvas.GetTop(this.Rec) + distance * Math.Cos(-this.Radian) +
0.5 * distance * (1 - Math.Cos(-this.Radian)));
Canvas.SetLeft(this.Rec,
Canvas.GetLeft(this.Rec) + distance * Math.Sin(-this.Radian) -
(0.5 * distance * Math.Sin(-this.Radian)));
Rec.Height -= distance;
}
e.Handled = true;
}
private void CalculateLastPoint()
{
var generalTransformStart1 = RightUpper.TransformToVisual(canvas);
var posEnd1 = generalTransformStart1.TransformPoint(new Point(RightUpper.ActualWidth/2,RightUpper.ActualHeight/2));
LastPointUpperRight = posEnd1;
}
如果您有任何建议,请告诉我。 谢谢!!!