我正在寻找通过触摸或鼠标旋转 WinRT xaml 圆形按钮或图像(如立体声收音机按钮)的示例代码。想法是能够以无限的方式触摸控件向左向右旋转。增量值用于增加或减少另一个对象的值。旋转角度并不重要。只是将控件向右或向左转动的动作是。
任何关于实现这一目标的好方法的提示将不胜感激?
这里的部分代码:
private RotateTransform rotateTransform;
void ManipulationStarting(object sender, ManipulationStartingRoutedEventArgs e)
{
e.Handled = true;
var image = sender as Image;
var container = image.Parent as UIElement;
var localCenter = new Point(image.ActualWidth / 2, image.ActualHeight / 2);
var pivot = new ManipulationPivot(localCenter, 20);
e.Pivot = pivot;
rotateTransform.CenterX = image.ActualWidth / 2;
rotateTransform.CenterY = image.ActualHeight / 2;
e.Container = container;
}
void ImageManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
e.Handled = true;
var image = sender as Image;
double newAngle;
var valueDrawline = 1;
if (e.Delta.Rotation < 0)
{
valueDrawline = -1;
newAngle = rotateTransform.Angle - (1 + e.Delta.Rotation);
}
else
{
valueDrawline = 1;
newAngle = rotateTransform.Angle + (1 + e.Delta.Rotation);
}
rotateTransform.Angle = newAngle;
image.RenderTransform = rotateTransform;
}
“真正的”问题来自不恒定的方向。例如:当我用鼠标或手指从左到右转动控件时,该值应该增加+1。这不适用于当前代码,因为该值主要以 +1 递增,但即使我仍然转向该方向,也以 -1 递增。为了更清楚,让我们假设我想用我的控件绘制一条水平线。我需要将其向右旋转以向右绘制,反之以向左绘制。使用此代码,它会朝着正确的方向前进,但沿线的路径要退很多步...
提前发送