多手势UIGestureRecognizer(iPhone,Cocos2d) [英] Multiple Gestures for UIGestureRecognizers (iPhone, Cocos2d)

查看:138
本文介绍了多手势UIGestureRecognizer(iPhone,Cocos2d)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用cocos2d的渲染一个精灵,而UIGestureRecognizers允许用户平移,旋转和缩放的精灵。



我得在每个工作隔离使用如下代码:

  UIPinchGestureRecognizer * pinchRecognizer = [[[UIPinchGestureRecognizer页头] initWithTarget:层动作:@selector(handlePinchFrom :)] autorelease]; 
[viewController.view addGestureRecognizer:pinchRecognizer];

UIRotationGestureRecognizer * rotationRecognizer = [[[UIRotationGestureRecognizer页头] initWithTarget:层的行动:@选择(handleRotationFrom :)]自动释放];
[viewController.view addGestureRecognizer:rotationRecognizer];

然而,我想同时缩放和旋转sprite,如果用户捏住他们的手指在一起旋转照片应用程序做到这一点,例如)。不幸的是,识别器似乎停留在旋转或捏模式,并且不会同时调用两个处理程序:(



基本上,我想知道 - 这是否意味着我不能使用UIGestureRecognizers我可以合并两个识别并做在一个单一的处理程序的行为,我会要继承UIGestureRecognizer是像PinchAndRotateRecognizer

帮助:)

解决方案

只需实现gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:在您的委托。



我有一个 UIPinchGestureRecognizer ,一个 UIPanGestureRecognizer UIRotationGestureRecognizer 设置,我希望他们都工作在同一时间。我也有一个 UITapGestureRecognizer ,我做要同时识别。我所做的是这样的:

   - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer应该识别同时WithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer 
{
if(![gestureRecognizer isKindOfClass:[UITapGestureRecognizer class]]&&![otherGestureRecognizer isKindOfClass:[UITapGestureRecognizer class]]){
return YES;
}

return NO;
}


I'm using Cocos2d to render a sprite, and UIGestureRecognizers to allow the user to Pan, Rotate and Scale the sprite.

I've got each working in isolation using code like the following:

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];

However, I want to both scale and rotate the sprite if the user pinches their fingers together whilst rotating (the Photos app does this, for instance). Unfortunately though, the recognizer seems to get stuck in either "rotate" or "pinch" mode, and won't call both handlers at the same time :(

So, basically, I want to know - does this mean I can't use UIGestureRecognizers? Can I combine two recognizers and do all of the actions in a single handler? Will I have to subclass UIGestureRecognizer to be something like "PinchAndRotateRecognizer".

Help appreciated :)

解决方案

Just implement gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer: in your delegate.

I have a UIPinchGestureRecognizer, a UIPanGestureRecognizer and a UIRotationGestureRecognizer set up and I want them all to work at the same time. I also have a UITapGestureRecognizer which I do not want to be recognized simultaneously. All I did was this:

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

    return NO;
}

这篇关于多手势UIGestureRecognizer(iPhone,Cocos2d)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆