在Windows Phone 8上平滑捏缩放和平移

我已经设法通过连接到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手机用户界面的平滑度相比,它感觉非常平静和僵硬。 机芯没有惯性。

有没有办法让运动更顺畅? 使用动画和故事板是一种方法吗? 我已经尝试使用ScrollView至少获得平滑的平移但是ManipulationDelta事件没有正确触发。

我知道你在谈论8,我会发布一篇与7相关的文章的链接,但是在玩Windows Phone时非常有用,所以这里有:

http://www.wintellect.com/cs/blogs/jprosise/archive/2011/01/19/building-touch-interfaces-for-windows-phones-part-3.aspx

我不认为从那以后发生很大变化……

我想从数学的角度来看是正确的。 结果与Telerik的PanAndZoomImage的正确性相似。 如果你不感兴趣,直接跳到这个要点 (它适用于WP7.1 +)。 您需要引用System.Windows.Interactivity和Windows Phone工具包。

用法:

      

数学

平移和缩放使用CompositeTransform的4个转换中的2个,即Translation和Scaling。 关键是要了解如何组合这两个scale + translate变换。 我会使用haskellish表示法,因为输入和阅读的负担较小。 我们的“原始人”是

  1. scale s =围绕(sx,sy)的比例,x方向的因子sx和y方向的sy
  2. translate t =在x方向上将所有点偏移tx,在y方向上偏移ty

CompositeTransform围绕中心点缩放,表示为

 scaleAround cs = translate c . scale s . translate -c 

以下规则成立(如果您不相信我,那么所有运算符都是分数):

  1. translate a . translate b = translate (a+b)
  2. scale a . scale b = scale (a*b)
  3. translate t . scale s = scale s . translate (t/s)

CompositeTransform就像

 transform sct = translate t . scaleAround cs = translate (t+c) . scale s . translate -c 

在编写其中两个变换时,我们必须移动基元,直到我们到达上面的这种forms。 设ab为那两个CompositeTransforms。 所以我们得到:

 transform' = b . a = translate bt . scaleAround bc bs . translate at . scaleAround ac as = translate bt . translate bc . scale bs . translate -bc . translate at . translate ac . scale as . translate -ac = translate (bt+bc) . scale bs . translate (ac+at-bc) . scale as . translate -ac = translate (bt+bc) . translate (ac+at-bc)*bs . scale bs . scale as . translate -ac = translate (bt+bc+(ac+at-bc)*bs) . scale (as*bs) . translate -ac = translate (bt+bc-ac+(ac+at-bc)*bs) . scaleAround ac (as*bs) = translate (bt+at*bs+(bs-1)*(ac-bs)) . scaleAround ac (as*bs) 

这只是因为我对某些人做某些事情的深刻文献感到沮丧。

对于实际的组合代码,请看这里

我知道这是一个迟到的答案,但这是另一个可以帮助解决这个问题的示例项目http://code.msdn.microsoft.com/wpapps/Smooth-flick-and-zoom-with-7760c7f7