我有图层,我在其上放置了精灵(黄色)和子菜单(“主菜单:按钮),看起来像模态对话框。该图层下方还有许多按钮,菜单。我想要实现的是每当这个图层呈现,不要将触摸事件传播到其他项目。这是我在图层类中所做的:
- (id)init {
...
// I was hoping that this will take touch and eat, so if I tap on button it will not be propagated further, because it has lowest priority
[_menu setHandlerPriority:INT_MIN+1];
...
}
-(void)registerWithTouchDispatcher {
// With this I was hoping that if I tap anywhere else my layer class will capture it first
[[[CCDirector sharedDirector] touchDispatcher] addTargetedDelegate:self priority:INT_MIN+2 swallowsTouches:YES];
}
-(BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
// so I simply drop any tap on my layer
return NO;
}
可能我遗漏了一些东西,但是我的图层下方的这个按钮仍然可以触摸。所以模态概念不起作用。
我怎样才能使我的黄色精灵的所有子项目都可触摸,而其余的不可触摸。