问题
I'm using the UIPinchRecognizer and an open pinch to detect when someone 'pulls apart' a sprite in a Box2D world.
The problem is that when you drag two items toward each other it detects this as a close pinch and breaks all my touchjoints and the movement of the box2d objects.
I've tried to split my problem into two questions - the question you're reading now: is it is possible to suppress the close pinch, and if that's not possible: how to detect an open pinch myself.
I need to either suppress the detection of close pinches or write my own open pinch detection.
I tried returning from the pinch gesture method on an open pinch like this:
if (pinch.velocity < 0) {
//close pinch
return;
}
but it doesn't work because it still breaks the touch joints / box2d objects.
Could you help me solve this problem by suppressing the detection of close pinches?
回答1:
I need to check this on a device, but I think that this has fixed it:
//Multitouch / pinch?
UIPinchGestureRecognizer *pinchRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchGesture:)];
pinchRecognizer.cancelsTouchesInView = NO; //This fixes it because it stops the mouse joints getting broken.
[[[CCDirector sharedDirector] openGLView] addGestureRecognizer:pinchRecognizer];
[UIPinchGestureRecognizer release];
with this in the pinchGesture method:
if(pinch.velocity <0 ){
return;
}
来源:https://stackoverflow.com/questions/10185420/uipinchgesturerecognizer-suppress-close-pinch-detection