Multiple Gestures for UIGestureRecognizers (iPhone, Cocos2d)(UIGestureRecognizers (iPhone, Cocos2d) 的多种手势)
问题描述
我正在使用 Cocos2d 来渲染精灵,并使用 UIGestureRecognizers 来允许用户平移、旋转和缩放精灵.
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 :(
所以,基本上,我想知道 - 这是否意味着我不能使用 UIGestureRecognizers?我可以组合两个识别器并在一个处理程序中执行所有操作吗?我是否必须将 UIGestureRecognizer 子类化为类似于PinchAndRotateRecognizer"的东西.
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".
帮助表示赞赏:)
推荐答案
只需实现gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer: 在您的委托中.
Just implement gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer: in your delegate.
我设置了一个 UIPinchGestureRecognizer
、一个 UIPanGestureRecognizer
和一个 UIRotationGestureRecognizer
,我希望它们都能同时工作.我还有一个 UITapGestureRecognizer
我确实不希望同时被识别.我所做的只是:
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;
}
这篇关于UIGestureRecognizers (iPhone, Cocos2d) 的多种手势的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:UIGestureRecognizers (iPhone, Cocos2d) 的多种手势
基础教程推荐
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01