2014-03-03 184 views
0

我做了一个我称之为ScrollNode的CCNode,基本上它是一个CCNode,它裁剪了一个子节点的某个区域,并且这个子节点正在基于该scroll的x和y位置上移动透明覆盖UIScrollView的位置。Cocos2d和UISCrollview通过触摸

我想要一个Cocos2d中的ScrollView,这对于iOS平台来说是原生的,它做得很好。

然而,这样的处理事情出现了问题。在可以滚动的节点上触摸CCButton不会被调用(因为在该区域上有透明的UIScrollView),当它是“轻击”手势而不是“平移手势”时,可以从UIScrollView传递触摸“

我曾尝试以下:

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

但是,这似乎并没有任何区别。

亲切的问候,

回答

0

好像我修好了。我已经分类了UIScrollView,并将触动*事件传递给它的父项。这似乎对滚动没有影响,但确保它确实触发CCButton的轻击事件。

#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 
1

我更愿意解决这个问题的方法是建立自己UITapGestureRecognizerUIScrollView实例。处理程序然后将触摸位置传递给处理场景中的水龙头的代码。

轻拍和平移手势识别器知道如何互相交互,因此它仍然提供本机体验。