最上層には、タッチを受け取る「戻るボタン」スプライトがあります。通常、他のすべてのタッチは下位レイヤーにパススルーする必要がありますが、この [戻る] ボタンがタップ ジェスチャを受け取ると、タッチを飲み込む必要があります。
現在、[戻る] ボタンへのタッチは、下のレイヤーへのタッチとしても受信されています。
上層:
-(id) init {
if ((self = [super init])) {
[self scheduleUpdate];
// Initialize KKInput
KKInput* input = [KKInput sharedInput];
input.gestureTapEnabled = input.gesturesAvailable;
...
}
return self;
}
...
-(void) update:(ccTime)delta
{
KKInput* input = [KKInput sharedInput];
if (input.gestureTapRecognizedThisFrame) {
CCLOG(@"Top layer tap recognized");
if ([self.backButton containsPoint:input.gestureTapLocation]) {
CCLOG(@"Top layer Back Button tap recognized");
}
}
}
下層
-(id) init {
if ((self = [super init])) {
[self scheduleUpdate];
// Initialize KKInput
KKInput* input = [KKInput sharedInput];
input.gestureTapEnabled = input.gesturesAvailable;
...
}
return self;
}
...
-(void) update:(ccTime)delta
{
KKInput* input = [KKInput sharedInput];
if (input.gestureTapRecognizedThisFrame) {
CCLOG(@"Lower layer tap recognized");
}
}
[戻る] ボタン以外の場所をタップすると、必要な出力が得られます。
2012-10-16 10:58:03.747 MyApp[13838:707] Top layer tap recognized
2012-10-16 10:58:03.749 MyApp[13838:707] Lower layer tap recognized
しかし、[戻る] ボタンをタップすると、タップはボタンに飲み込まれません。
2012-10-16 10:49:23.426 MyApp[13838:707] Top layer tap recognized
2012-10-16 10:49:23.429 MyApp[13838:707] Top layer Back Button tap recognized
2012-10-16 10:49:23.434 MyApp[13838:707] Lower layer tap recognized