【问题标题】:pinch to zoom,drag an image anywhere on the screen in windows phone 8 apps捏缩放,在 Windows Phone 8 应用程序的屏幕上任意位置拖动图像
【发布时间】:2014-10-22 14:03:34
【问题描述】:

再次大家好。最近我为 windows phone 8 设备创建了换脸应用程序,我设计了一个带有两个图像控件的页面

第一张图片作为背景,第二张图片控制是前景。

我已将“GestureListener”添加到我的第一个图像控件(背景)中,我必须使用“toolkit:GestureService.GestureListener”“捏、放大、缩小、拖动”该背景图像。

我做的一切都很好,就像我可以成功地捏、缩放、拖动图像一样......但是,

问题是“我无法从我触摸屏幕上的手指的任何地方捏或拖动图像”。所以捏缩放或拖动对我来说很难放大/缩小或拖动图像。,

但在 I-Phone/i-pad/i-pod 和所有 Android 设备中,我可以通过捏合来放大/缩小或从触摸屏幕上的任意位置拖动图像。,

就像我已经说过的,我的第一张图片是背景,可以添加手势控制,第二张图片是普通图片控制,不能缩放或拖动。,

这是我的代码。,

我的 XAML 代码:

<Grid x:Name="ContentPanel" Grid.RowSpan="2">
    <Canvas x:Name="screenArea" Width="400" Height="580" >

        <Image x:Name="myImage" Width="400" Height="580"  RenderTransformOrigin="0.5, 0.5" CacheMode="BitmapCache" >
            <Image.RenderTransform>
                <TransformGroup>
                    <CompositeTransform x:Name="MyMustacheTransformation" />
                </TransformGroup>
            </Image.RenderTransform>
            <toolkit:GestureService.GestureListener>
                <toolkit:GestureListener PinchStarted="OnPinchStarted"
                                         PinchDelta="OnPinchDelta"
                                         DragDelta="OnDragDelta"/>
            </toolkit:GestureService.GestureListener>
        </Image>
        <Image x:Name="frameImage" Width="400" Height="580" Stretch="Fill"/>
    </Canvas>
</Grid>

而我的 pinch_start、Drag_delta、pinch_delta 的 CS 代码是

private void OnPinchStarted(object sender, PinchStartedGestureEventArgs e)
{
    _initialAngle = MyMustacheTransformation.Rotation;
    _initialScale = MyMustacheTransformation.ScaleX;
}

private void OnPinchDelta(object sender, PinchGestureEventArgs e)
{
    MyMustacheTransformation.Rotation = _initialAngle + e.TotalAngleDelta;
    MyMustacheTransformation.ScaleX = _initialScale * e.DistanceRatio;
    MyMustacheTransformation.ScaleY = _initialScale * e.DistanceRatio; 
}

private void OnDragDelta(object sender, DragDeltaGestureEventArgs e)
{
    Image rect = sender as Image;
    TranslateTransform transform = rect.RenderTransform as TranslateTransform;

    MyMustacheTransformation.TranslateX += e.HorizontalChange;
    MyMustacheTransformation.TranslateY += e.VerticalChange;
}

我希望你能理解我的要求,如果我的话不清楚,我很抱歉,

如果您已经在 Android/i-phone/pod/pad 设备上使用过换脸应用程序,则意味着他们可以轻松理解所期待的内容。

我的目标是:

“我可以通过捏合来放大/缩小,从触摸布局上的任何位置拖动图像.. 就像在 i-phone/pod/pad 和 android 设备中一样”

我已经挣扎了几个星期。请给出一些解决方案。

我你提供的任何示例代码意味着对我更有用。,

在此先感谢各位。,

【问题讨论】:

    标签: c# wpf windows-phone-7 windows-phone-8 pinchzoom


    【解决方案1】:

    问题是您将GestureListener 附加到图像上,因此您只能在触摸图像时获得手势。

    将监听器附加到最外层的Grid

    【讨论】:

    • 我终于得到了我所期待的。非常感谢为我花费宝贵时间的所有人。感谢堆栈溢出。,
    猜你喜欢
    • 2011-09-08
    • 2012-12-18
    • 1970-01-01
    • 1970-01-01
    • 2014-06-11
    • 2013-01-17
    • 1970-01-01
    • 1970-01-01
    • 2012-06-17
    相关资源
    最近更新 更多