【发布时间】:2013-01-17 03:19:20
【问题描述】:
我已经通过连接到 ManipulationDelta 和 ManipulationStarted 事件(在图像控件上)实现了捏缩放和平移:
private void image_OnManipulationDelta(object sender, ManipulationDeltaEventArgs e)
{
var transform = (CompositeTransform)image.RenderTransform;
// pan
transform.TranslateX = _translationX + e.CumulativeManipulation.Translation.X;
transform.TranslateY = _translationY + e.CumulativeManipulation.Translation.Y;
// zoom
if (e.PinchManipulation != null)
{
transform.CenterX = e.PinchManipulation.Original.Center.X;
transform.CenterY = e.PinchManipulation.Original.Center.Y;
transform.ScaleX = _scaleX * e.PinchManipulation.CumulativeScale;
transform.ScaleY = _scaleY * e.PinchManipulation.CumulativeScale;
}
}
private void image_OnManipulationStarted(object sender, ManipulationStartedEventArgs e)
{
// the user has started manipulating the screen, set starting points
var transform = (CompositeTransform)image.RenderTransform;
_scaleX = transform.ScaleX;
_scaleY = transform.ScaleY;
_translationX = transform.TranslateX;
_translationY = transform.TranslateY;
}
但与 windows phone UI 其余部分的流畅度相比,它感觉非常平静和僵硬。运动没有惯性。
有没有办法让动作更流畅?使用动画和故事板是一种解决方法吗?我已经尝试使用 ScrollView 至少获得平滑平移,但是 ManipulationDelta 事件没有正确触发。
【问题讨论】:
-
只是一个更新,因为这个问题似乎很受欢迎:我最终使用上面的代码结合以编程方式创建的动画来获得“惯性”的感觉。我还必须通过使用简单的控件(画布和位图缓存图像)进行优化,以使其顺利运行。
标签: c# .net windows-phone-8