Question

I am using UIPinchGestureRecognizer.can i write two action for pinch in and pinch out..is there any specific Method(delegate)?I have written only one it is called when i pinched in...

  UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinchGesture:)];
[self.view addGestureRecognizer:pinchGesture]; 
[pinchGesture release];
Was it helpful?

Solution

You could check the gesture's .scale in -handlePinchGesture:. If it is < 1, it is a pinch-in, otherwise is a pinch-out.

OTHER TIPS

// 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;
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top