Detect an open pinch - like UIPinchGestureRecogniz

2019-09-01 08:32发布

问题:

I'm using the UIPinchRecognizer and an open pinch to detect when someone 'pulls apart' a sprite in a Box2D world.

If I use UIPinchGestureRecognizer to detect pull aparts, it breaks my mouse joints when two objects are dragged together - which is less than ideal. I've tried to split my problem into two questions - how to detect an open pinch without UIPinchGestureRecognizer and is it is possible to suppress the close pinch.

How can I write my own class to detect an open pinch? That is, two fingers on an object moving apart? This is pretty daunting for me and I'm not sure where to start. It looks like you can subclass UIGestureRecognizer to help in these situations.

UPDATE

Here's what I want to achieve.

  1. The user puts two fingers on an box2d /sprite object
  2. The user pulls those fingers apart, like an open pinch
  3. The object splits in half (I've implemented this bit)

That's the only time I need the UIPinchGestureRecognizer. The user will be moving multiple objects around with multiple fingers - I don't want the pinch gesture to be triggered when different objects are being moved toward one another.

I made a really amazing diagram showing what I want - the blue bits represent touches/direction. Please excuse my mad photoshop skills: