UIPinchGestureRecognizer - Suppress 'close pinch' detection

こ雲淡風輕ζ 提交于 2019-12-12 05:32:35

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!