Xamarin表单 - 仅在图像而不是整个屏幕上使用捏合手势

时间:2018-04-03 09:37:22

标签: c# xaml xamarin.forms

在Xamarin Forms中,我们如何限制捏合手势仅缩放图像而不是整个屏幕?

我在XAML中有以下内容,并认为在PinToZoomContainer中包装我的图像会这样做,但它仍会缩放整个屏幕。

<local:ContentRatioContainer>
    <local:PinchToZoomContainer>
        <local:PinchToZoomContainer.Content>
            <Image Aspect="AspectFill" Source="{Binding PreviewImage}" AbsoluteLayout.LayoutBounds="1,1,1,1" AbsoluteLayout.LayoutFlags="All" x:Name="bigImg" >
                <Image.GestureRecognizers>
                    <PinchGestureRecognizer PinchUpdated="OnPinchUpdated" />
                </Image.GestureRecognizers>
            </Image>
        </local:PinchToZoomContainer.Content>
    </local:PinchToZoomContainer>
</local:ContentRatioContainer>


public PinchToZoomContainer()
{
     var pinchGesture = new PinchGestureRecognizer();
     pinchGesture.PinchUpdated += OnPinchUpdated;
     GestureRecognizers.Add(pinchGesture);
}

1 个答案:

答案 0 :(得分:0)

通过

纠正此问题
public PinchToZoomContainer()
{
     var pinchGesture = new PinchGestureRecognizer();
     pinchGesture.PinchUpdated += OnPinchUpdated;
     bigImg.GestureRecognizers.Add(pinchGesture);
}