How to detect pinch in gesture vs pinch out gesture?

user1337645 picture user1337645 · Jun 24, 2012 · Viewed 7.5k times · Source

Instead of scaling, which I think pinch gesture is usually used for, I am looking to just detect whether the pinch was a pinch in vs pinch out so I can collapse or expand some table sections. How would I go about doing that?

Answer

ScorpionKing2k5 picture ScorpionKing2k5 · Dec 26, 2012

The "scale" property is less than 1 for pinch-in gesture and greater than 1 for pinch-out. This happens for all pinches with 2 fingers.

What I also observed was that if I pinched in with 5 fingers (which is the shortcut to minimize-to-home), the scale value comes exactly 1.0 - everytime. But this is not supported by any Apple documentation that I'm aware of.

You can experiment what the values are coming by simply putting an NSLog in your pinch handling selector

NSLog(@"Scale: %.2f | Velocity: %.2f",pinch.scale,pinch.velocity);