Xamarin.Forms在ScrollView问题中的挤压手势

Xamarin.Forms在ScrollView问题中的挤压手势,xamarin,xamarin.forms,Xamarin,Xamarin.forms,我是Xamarin.Forms的新手,我一直在尝试制作一个简单的程序。我想制作一个可以平移和缩放图像的程序。我在这个网站上找到了处理捏手势和视图缩放()的代码。然后,我尝试使用此代码扩展“ScrollView”类 当我在iOS上运行代码时,它在模拟器中运行良好。(缩放有点笨重,但我不知道是模拟器还是技术) 当我在Android(模拟器或实际设备)上运行代码时,页面只会滚动。在模拟器上,我使用命令键来调用挤压手势。我看到合适的捏手势界面出现了,但它看起来像滚动视图截取了作为平移手势的手势 当我将S

我是Xamarin.Forms的新手,我一直在尝试制作一个简单的程序。我想制作一个可以平移和缩放图像的程序。我在这个网站上找到了处理捏手势和视图缩放()的代码。然后,我尝试使用此代码扩展“ScrollView”类

当我在iOS上运行代码时,它在模拟器中运行良好。(缩放有点笨重,但我不知道是模拟器还是技术)

当我在Android(模拟器或实际设备)上运行代码时,页面只会滚动。在模拟器上,我使用命令键来调用挤压手势。我看到合适的捏手势界面出现了,但它看起来像滚动视图截取了作为平移手势的手势

当我将ScrollView类从混合中取出(并简单地将其设置为ContentView类)时,挤压手势在两种平台上都可以正常工作

有什么想法吗

这是我的容器的代码(几乎是上面链接中代码的精确副本)


答案就在Android、IOS项目的开发中

查看本指南:


建议创建一个android和ios平台支持的渲染,以便在ScrollView上放大应用程序。

您能解决这个问题吗?我有同样的问题…同样的问题…有人能帮忙吗…你能解决这个问题吗?
using System;
using Xamarin.Forms;

namespace ImageTest
{
public class PinchToZoomContainer : ScrollView
{
double currentScale = 1;
double startScale = 1;
double xOffset = 0;
double yOffset = 0;

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

    public void OnPinchUpdated(object sender, PinchGestureUpdatedEventArgs e)
    {
        if (e.Status == GestureStatus.Started)
        {
            // Store the current scale factor applied to the wrapped user interface element,
            // and zero the components for the center point of the translate transform.
            startScale = Content.Scale;
            Content.AnchorX = 0;
            Content.AnchorY = 0;
        }
        if (e.Status == GestureStatus.Running)
        {
            // Calculate the scale factor to be applied.
            currentScale += (e.Scale - 1) * startScale;
            currentScale = Math.Max(0.1, currentScale);

            // The ScaleOrigin is in relative coordinates to the wrapped user interface element,
            // so get the X pixel coordinate.
            double renderedX = Content.X + xOffset;
            double deltaX = renderedX / Width;
            double deltaWidth = Width / (Content.Width * startScale);
            double originX = (e.ScaleOrigin.X - deltaX) * deltaWidth;

            // The ScaleOrigin is in relative coordinates to the wrapped user interface element,
            // so get the Y pixel coordinate.
            double renderedY = Content.Y + yOffset;
            double deltaY = renderedY / Height;
            double deltaHeight = Height / (Content.Height * startScale);
            double originY = (e.ScaleOrigin.Y - deltaY) * deltaHeight;

            // Calculate the transformed element pixel coordinates.
            double targetX = xOffset - (originX * Content.Width) * (currentScale - startScale);
            double targetY = yOffset - (originY * Content.Height) * (currentScale - startScale);

            // Apply translation based on the change in origin.
            Content.TranslationX = targetX.Clamp(-Content.Width * (currentScale - 1), 0);
            Content.TranslationY = targetY.Clamp(-Content.Height * (currentScale - 1), 0);

            // Apply scale factor
            Content.Scale = currentScale;
        }
        if (e.Status == GestureStatus.Completed)
        {
            // Store the translation delta's of the wrapped user interface element.
            xOffset = Content.TranslationX;
            yOffset = Content.TranslationY;
        }
    }
}

}