Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/103.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 如何区分轻触和拖动_Objective C_Ios_Cocos2d Iphone_Touch_Gesture Recognition - Fatal编程技术网

Objective c 如何区分轻触和拖动

Objective c 如何区分轻触和拖动,objective-c,ios,cocos2d-iphone,touch,gesture-recognition,Objective C,Ios,Cocos2d Iphone,Touch,Gesture Recognition,我正在创建一个应用程序,我正在尝试创建它,这样我就可以在屏幕上拖动一个精灵(上面有第二个精灵),但是如果我只是点击精灵,应该会调用其他方法 当我触摸精灵的边缘时,我可以很好地进行拖动,但是当我尝试从精灵的中间(第二个精灵位于顶部)拖动时,拖动根本不起作用,但是会调用水龙头 我知道为什么他不这么做,但是,两个精灵的触球都有冲突,因为上面的那个在触到下面的第二个之前吞下了触球 如果手指移动,我希望精灵拖动,但我希望在只进行点击时点击注册(即手指没有在屏幕上移动),我将如何实现这一点 我正在使用的精灵

我正在创建一个应用程序,我正在尝试创建它,这样我就可以在屏幕上拖动一个精灵(上面有第二个精灵),但是如果我只是点击精灵,应该会调用其他方法

当我触摸精灵的边缘时,我可以很好地进行拖动,但是当我尝试从精灵的中间(第二个精灵位于顶部)拖动时,拖动根本不起作用,但是会调用水龙头

我知道为什么他不这么做,但是,两个精灵的触球都有冲突,因为上面的那个在触到下面的第二个之前吞下了触球

如果手指移动,我希望精灵拖动,但我希望在只进行点击时点击注册(即手指没有在屏幕上移动),我将如何实现这一点

我正在使用的精灵的视觉效果(如果有帮助):

黄色符文是一个独立于它下面的石头的精灵(因为有动画参与)

-----触按可选择顶部精灵----------
-(BOOL)cctouch开始:(UITouch*)触摸事件:(UIEvent*)事件{
lastTouchLocation=[RuneScene locationFromTouch:touch];
BOOL isTouchHandled=CGRectContainsPoint([charSprite boundingBox],lastTouchLocation);
已办理退货手续;
}
-(无效)ccTouchEnded:(UITouch*)触摸事件:(UIEvent*)事件{
NSLog(@“Tap received!”);
}
------触摸底部精灵--------
-(BOOL)cctouch开始:(UITouch*)触摸事件:(UIEvent*)事件{
lastTouchLocation=[RuneScene locationFromTouch:touch];
BOOL=否;
//检查此触摸是否在蜘蛛的精灵上。
if(CGRectContainsPoint([current.runeSprite boundingBox],lastTouchLocation)){
移动器=电流;
Istouch=是;
}
else if(CGRectContainsPoint([rune1.runeSprite boundingBox],lastTouchLocation)){
mover=rune1;
Istouch=是;
}
else if(CGRectContainsPoint([rune2.runeSprite boundingBox],lastTouchLocation)){
mover=rune2;
Istouch=是;
}else if(CGRectContainsPoint([rune3.runeSprite boundingBox],lastTouchLocation)){
mover=rune3;
Istouch=是;
}else if(CGRectContainsPoint([rune4.runeSprite boundingBox],lastTouchLocation)){
mover=rune4;
Istouch=是;
}else if(CGRectContainsPoint([rune5.runeSprite boundingBox],lastTouchLocation)){
mover=rune5;
Istouch=是;
}else if(CGRectContainsPoint([rune6.runeSprite boundingBox],lastTouchLocation)){
mover=rune6;
Istouch=是;
}else if(CGRectContainsPoint([rune7.runeSprite boundingBox],lastTouchLocation)){
mover=rune7;
Istouch=是;
}else if(CGRectContainsPoint([rune0.runeSprite boundingBox],lastTouchLocation)){
mover=rune0;
Istouch=是;
}
//停止移动操作,以免干扰用户的滚动。
//[self-stopActionByTag:ActionTagCastingLayerMovesBack];
//总是吞下触摸,游戏层是最后一层接受触摸。
已办理退货手续;
}
-(无效)ccTouchMoved:(UITouch*)触摸事件:(UIEvent*)事件{
CGPoint currentTouchLocation=[RuneScene locationFromTouch:touch];
//将电流差取到最后一个触摸位置。
CGPoint moveTo=ccpSub(lastTouchLocation,currentTouchLocation);
//然后将其反转,因为目标不是给人在背景上移动相机的印象,
//但是触摸和移动背景。
moveTo=ccpMult(moveTo,-1);
lastTouchLocation=currentTouchLocation;
[带位置的自动移动:移动到];
}
-(无效)ccTouchEnded:(UITouch*)触摸事件:(UIEvent*)事件{
如果(!current.isPlaced&&mover==current&¤tR
我尝试查看UITapGestureRecognitor,但我为实现它所做的一切都不起作用。我的层/精灵不允许我将它们添加为手势。我也在cocos2d论坛上读到了一些关于CCGrstureRecognizer的东西,但是我找不到任何关于这个类的文档,也找不到如何实际使用它


这里有人知道如何帮助我解决问题吗?

而不是使用(如果CGRectContainsPoint)尝试使用视图的pointInside:withEvent:返回否。这将导致系统表现为您的视图根本不在那里。

FWIW Kobold2D为手势识别器提供了一个超级简单的包装:哈,我没想到我读的书的作者会对我的问题发表评论。那么我猜我是西班牙宗教法庭。;)请你详细说明一下好吗?当然可以。如果希望忽略顶部的一个,并将触摸传递到下一个,则视图的pointInside:withEvent:method将返回NO。
--------Touch for the top sprite----------
-(BOOL) ccTouchBegan:(UITouch*)touch withEvent:(UIEvent *)event{
    lastTouchLocation = [RuneScene locationFromTouch:touch];
    BOOL isTouchHandled = CGRectContainsPoint([charSprite boundingBox], lastTouchLocation);

    return isTouchHandled;
}
-(void) ccTouchEnded:(UITouch*)touch withEvent:(UIEvent *)event{
    NSLog(@"Tap received!");

}

------Touch for the bottom sprite--------

-(BOOL) ccTouchBegan:(UITouch*)touch withEvent:(UIEvent *)event{
    lastTouchLocation = [RuneScene locationFromTouch:touch];
    BOOL isTouchHandled = NO;

    // Check if this touch is on the Spider's sprite.
    if (CGRectContainsPoint([current.runeSprite boundingBox], lastTouchLocation)){
        mover = current;
        isTouchHandled = YES;
    }
    else if(CGRectContainsPoint([rune1.runeSprite boundingBox], lastTouchLocation)){
        mover = rune1;
        isTouchHandled = YES;
    }
    else if(CGRectContainsPoint([rune2.runeSprite boundingBox], lastTouchLocation)){
        mover = rune2;
        isTouchHandled = YES;
    }else if(CGRectContainsPoint([rune3.runeSprite boundingBox], lastTouchLocation)){
        mover = rune3;
        isTouchHandled = YES;
    }else if(CGRectContainsPoint([rune4.runeSprite boundingBox], lastTouchLocation)){
        mover = rune4;
        isTouchHandled = YES;
    }else if(CGRectContainsPoint([rune5.runeSprite boundingBox], lastTouchLocation)){
        mover = rune5;
        isTouchHandled = YES;
    }else if(CGRectContainsPoint([rune6.runeSprite boundingBox], lastTouchLocation)){
        mover = rune6;
        isTouchHandled = YES;
    }else if(CGRectContainsPoint([rune7.runeSprite boundingBox], lastTouchLocation)){
        mover = rune7;
        isTouchHandled = YES;
    }else if(CGRectContainsPoint([rune0.runeSprite boundingBox], lastTouchLocation)){
        mover = rune0;
        isTouchHandled = YES;
    }

    // Stop the move action so it doesn't interfere with the user's scrolling.
    //[self stopActionByTag:ActionTagCastingLayerMovesBack];

    // Always swallow touches, GameLayer is the last layer to receive touches.
    return isTouchHandled;

}

-(void) ccTouchMoved:(UITouch*)touch withEvent:(UIEvent *)event{
    CGPoint currentTouchLocation = [RuneScene locationFromTouch:touch]; 

    // Take the difference of the current to the last touch location.
    CGPoint moveTo = ccpSub(lastTouchLocation, currentTouchLocation);

    // Then reverse it since the goal is not to give the impression of moving the camera over the background, 
    // but to touch and move the background.
    moveTo = ccpMult(moveTo, -1);

    lastTouchLocation = currentTouchLocation;

    [self moveActionWithLocation: moveTo];
}

-(void) ccTouchEnded:(UITouch*)touch withEvent:(UIEvent *)event{
    if (!current.isPlaced && mover == current && currentR < Rune6) {
        // Move the game layer back to its designated position.
        CCMoveTo* move = [CCMoveTo actionWithDuration:1 position:curPt];
        CCEaseIn* ease = [CCEaseIn actionWithAction:move rate:0.5f];
        //ease.tag = ActionTagCastingLayerMovesBack;
        [current.runeSprite runAction:ease];

        [current setIsPlaced:YES];
        current.charSprite = [characters objectAtIndex:currentR];
        current.charSprite.position = curPt;
        //charSprite.visible = YES;
        [current performSelector:@selector(fade:) withObject:current.charSprite afterDelay:1];
        [current reorderChild:current.charSprite z:10];

        [self updateCurrentRune:currentR];
        [self updateCurrentCastNum:currentP];
        [self reorderChild:current z:10];
    }
}