Cocos2d和UISCrollview通过触摸

时间:2014-03-03 13:29:02

标签: uiscrollview cocos2d-iphone uigesturerecognizer

我创建了一个名为ScrollNode的CCNode,基本上它是一个CCNode,用于裁剪子节点的某个区域,并且这个子节点根据透明覆盖的UIScrollView的滚动位置移动它的x和y位置

我想在Cocos2d中使用ScrollView,它感觉iOS平台原生,并且做得很好。

然而,这种处理事物的方式出现了问题。可以滚动的节点上的CCButton触摸不被调用(因为在该区域上有透明的UIScrollView)当它是“轻敲”手势而不是“平移手势”时,是否可以通过UIScrollView的触摸进行调用“

我尝试了以下内容:

// Make sure touches are passed trough all views
for(UIGestureRecognizer *recognizer in self.scrollView.gestureRecognizers)
{
    recognizer.cancelsTouchesInView = NO;
}

但这似乎没有任何区别。

亲切的问候,

2 个答案:

答案 0 :(得分:1)

我更喜欢解决此问题的方法是在UITapGestureRecognizer实例上设置我自己的UIScrollView。然后处理程序将触摸位置传递给处理场景中的点击的代码。

点击和平移手势识别器知道如何相互交互,因此它仍然提供原生体验。

答案 1 :(得分:0)

好像我已经修好了。我已经将UIScrollView子类化,并将touches *事件传递给它的父级。这似乎对滚动没有影响,但确保它确实触发了CCButtons的点击事件。

#import "ScrollNodeScrollView.h"

@implementation ScrollNodeScrollView

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self.superview touchesCancelled:touches withEvent:event];
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self.superview touchesBegan:touches withEvent:event];
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self.superview touchesMoved:touches withEvent:event];
}

- (void)touchesEnded:(NSSet *)aTouches withEvent:(UIEvent *)anEvent
{
    [self.superview touchesEnded:aTouches withEvent:anEvent];
}

@end
相关问题