UIGestureRecognizers的多个手势(iPhone,Cocos2d)

nik*_*ikz 6 iphone objective-c cocos2d-iphone

我正在使用Cocos2d渲染精灵,而UIGestureRecognizers允许用户平移,旋转和缩放精灵.

我使用以下代码隔离工作:

UIPinchGestureRecognizer *pinchRecognizer = [[[UIPinchGestureRecognizer alloc] initWithTarget:layer action:@selector(handlePinchFrom:)] autorelease];
[viewController.view addGestureRecognizer:pinchRecognizer];

UIRotationGestureRecognizer *rotationRecognizer = [[[UIRotationGestureRecognizer alloc] initWithTarget:layer action:@selector(handleRotationFrom:)] autorelease];
[viewController.view addGestureRecognizer:rotationRecognizer];
Run Code Online (Sandbox Code Playgroud)

但是,如果用户在旋转时将手指捏在一起,我想要缩放和旋转精灵(例如,照片应用会执行此操作).不幸的是,识别器似乎陷入"旋转"或"捏合"模式,并且不会同时调用两个处理程序:(

所以,基本上,我想知道 - 这是否意味着我不能使用UIGestureRecognizers?我可以组合两个识别器并在一个处理程序中执行所有操作吗?我是否必须将UIGestureRecognizer子类化为"PinchAndRotateRecognizer".

帮助赞赏:)

Joh*_*rug 27

只需在你的委托中实现gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:

我有一个UIPinchGestureRecognizer,一个UIPanGestureRecognizer和一个UIRotationGestureRecognizer设置,我希望他们所有人同时工作.我也有一个UITapGestureRecognizer,我也没有想同时认可.我所做的就是:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    if (![gestureRecognizer isKindOfClass:[UITapGestureRecognizer class]] && ![otherGestureRecognizer isKindOfClass:[UITapGestureRecognizer class]]) {
        return YES;
    }

    return NO;
}
Run Code Online (Sandbox Code Playgroud)