0

在我的顶层中,我有一个“后退按钮”精灵,它应该接收触摸。通常所有其他触摸都应该传递到较低层,但如果这个后退按钮接收到轻击手势,那么它应该吞下触摸。

目前,对“后退”按钮的任何触摸也会作为对下方图层的触摸而被接收。

顶层:

-(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
4

1 回答 1

0

要清除手势状态,您可以将其关闭并重新打开。如果您在处理第一个轻按手势的位置添加它,这应该可以解决问题:

input.gestureTapEnabled = NO;
input.gestureTapEnabled = YES;
于 2012-10-16T12:45:31.717 回答