2010-09-07 52 views
1

我使用UIPinchGestureRecognizer.can我寫兩個行動捏,捏out..is有任何具體的方法(委託)?我寫的只有一個我偷它叫...UIPinchGestureRecognizer問題

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

回答

8

您可以在-handlePinchGesture:中檢查手勢的.scale。如果是< 1,這是一個捏合,否則是一個捏。

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; 
    } 
} 
相關問題