1

我正在使用 UIPinchGestureRecognizer。我可以为捏合和捏出写两个动作吗.. 有没有特定的方法(委托)?我只写了一个当我捏合时调用的方法...

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

2 回答 2

8

你可以检查手势的.scalein -handlePinchGesture:。如果 < 1,则为捏合,否则为捏合。

于 2010-09-07T12:46:26.650 回答
0
// 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;
    }
}
于 2012-04-10T10:51:09.447 回答