我已经设法通过连接到 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 事件没有正确触发。