Domanda

Sto usando UIPinchGestureRecognizer.can scrivo due azione per pinch e pizzico out..is Esiste un metodo specifico (delegato)? Mi hanno scritto una sola è chiamata quando ho schiacciato in ...

  UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinchGesture:)];
[self.view addGestureRecognizer:pinchGesture]; 
[pinchGesture release];
È stato utile?

Soluzione

Si potrebbe verificare .scale del gesto -handlePinchGesture:. Se è <1, si tratta di un pinch-in, in caso contrario è un pinch-out.

Altri suggerimenti

// Zoom the image by the current scale

[Export("ScaleImage")]
void ScaleImage (UIPinchGestureRecognizer gestureRecognizer)
{
    AdjustAnchorPointForGestureRecognizer (gestureRecognizer);

    if (gestureRecognizer.State == UIGestureRecognizerState.Began || gestureRecognizer.State == UIGestureRecognizerState.Changed)
    {
        gestureRecognizer.View.Transform *= CGAffineTransform.MakeScale (gestureRecognizer.Scale, gestureRecognizer.Scale);

        // Reset the gesture recognizer's scale - the next callback will get a delta from the current scale.
        gestureRecognizer.Scale = 1;
    }
}   

void AdjustAnchorPointForGestureRecognizer (UIGestureRecognizer gestureRecognizer)
{
    if (gestureRecognizer.State == UIGestureRecognizerState.Began)
    {
        var image = gestureRecognizer.View;
        var locationInView = gestureRecognizer.LocationInView (image);
        var locationInSuperview = gestureRecognizer.LocationInView (image.Superview);

        image.Layer.AnchorPoint = new PointF (locationInView.X / image.Bounds.Size.Width, locationInView.Y / image.Bounds.Size.Height);
        image.Center = locationInSuperview;
    }
}

// Zoom the image by the current scale

[Export("ScaleImage")]
void ScaleImage (UIPinchGestureRecognizer gestureRecognizer)
{
    AdjustAnchorPointForGestureRecognizer (gestureRecognizer);

    if (gestureRecognizer.State == UIGestureRecognizerState.Began || gestureRecognizer.State == UIGestureRecognizerState.Changed)
    {
        gestureRecognizer.View.Transform *= CGAffineTransform.MakeScale (gestureRecognizer.Scale, gestureRecognizer.Scale);

        // Reset the gesture recognizer's scale - the next callback will get a delta from the current scale.
        gestureRecognizer.Scale = 1;
    }
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top