Las formas de Xamarin pellizcan y se juntan

He implementado tanto pan y pinch individualmente, y funciona bien. Ahora estoy tratando de usar pinch and pan juntos y veo algunos problemas. Aquí está mi código:

XAML:

<AbsoluteLayout x:Name="PinchZoomContainer">
  <controls:NavBar x:Name="NavBar" ShowPrevNext="true" ShowMenu="false" IsModal="true" />
  <controls:PanContainer  x:Name="PinchToZoomContainer">
    <Image x:Name="ImageMain" />
  </controls:PanContainer>
</AbsoluteLayout>

Pinch / Pan Gesture Add's:

var panGesture = new PanGestureRecognizer();
panGesture.PanUpdated += OnPanUpdated;
GestureRecognizers.Add(panGesture);

var pinchGesture = new PinchGestureRecognizer();
pinchGesture.PinchUpdated += OnPinchUpdated;
GestureRecognizers.Add(pinchGesture);

Método Pan:

void OnPanUpdated(object sender, PanUpdatedEventArgs e)
{
    switch (e.StatusType)
    {
        case GestureStatus.Started:
            startX = e.TotalX;
            startY = e.TotalY;
            Content.AnchorX = 0;
            Content.AnchorY = 0;

            break;
        case GestureStatus.Running:
            // Translate and ensure we don't pan beyond the wrapped user interface element bounds.
            Content.TranslationX = Math.Max(Math.Min(0, x + e.TotalX), -Math.Abs(Content.Width - App.ScreenWidth));
            Content.TranslationY = Math.Max(Math.Min(0, y + e.TotalY), -Math.Abs(Content.Height - App.ScreenHeight));
            break;

        case GestureStatus.Completed:
            // Store the translation applied during the pan
            x = Content.TranslationX;
            y = Content.TranslationY;
            break;
    }
}

Método de pellizco:

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;
        //ImageMain.AnchorX = 0;
        //ImageMain.AnchorY = 0;
    }
    if (e.Status == GestureStatus.Running)
    {
        // Calculate the scale factor to be applied.
        currentScale += (e.Scale - 1) * startScale;
        currentScale = Math.Max(1, currentScale);
        currentScale = Math.Min(currentScale, 2.5);
        // 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;
    }
}

Si apago cualquiera de los gestos y solo uso el otro, la funcionalidad funciona perfectamente. El problema surge cuando agrego los gestos de desplazamiento Y pellizco. Lo que parece estar sucediendo es esto:

1) La panorámica en realidad parece estar funcionando como se esperaba 2) Cuando explora la imagen inicialmente, digamos, mueva la imagen al centro Y y al centro X, y luego intente hacer zoom, la imagen se restablece estado inicial. Luego, cuando realiza un desplazamiento panorámico, lo lleva de regreso a donde estaba antes de intentar hacer zoom (por eso digo que el desplazamiento está funcionando bien).

Por lo que entiendo de mi depuración es que cuando haces zoom no tiene en cuenta la posición en la que te encuentras actualmente. Por lo tanto, cuando primero realiza una panorámica y luego hace zoom, no se acerca a la posición en la que se encuentra sino al punto inicial de la imagen. Luego, cuando intentas desplazarte desde allí, el método de desplazamiento aún recuerda dónde estabas y te mueve de regreso a donde estabas antes de intentar hacer zoom.

Con la esperanza de una idea de esto. Obviamente, hay un problema con mi método de pellizco. Solo creo que (obviamente no puedo entenderlo) necesito agregarle lógica que tenga en cuenta dónde estás actualmente.

Respuestas a la pregunta(3)

Su respuesta a la pregunta