在SKSpriteNode上滑动手势

时间:2014-05-24 10:49:44

标签: ios sprite-kit uigesturerecognizer uiswipegesturerecognizer skspritenode

我有spriteNode我需要在SKSpriteNode上进行滑动检测,但似乎滑动手势只能在视图上进行。有没有办法做到这一点?

SKSpriteNode *rabbit = [SKSpriteNode spriteNodeWithImageNamed:@"rabbit_img"];

UISwipeGestureRecognizer * swipeleft=[[UISwipeGestureRecognizer alloc]initWithTarget:self   action:@selector(handleSwipeGesture:)];
swipeleft.direction=UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:swipeleft];

1 个答案:

答案 0 :(得分:0)

您可以通过state property获取滑动的起始坐标。

- (void)swipe:(UISwipeGestureRecognizer *)recognizer
{
    CGPoint point = [recognizer locationInView:[recognizer view]];
    if (recognizer.state == UIGestureRecognizerStateBegan)
        NSLog(@"start coordinates: %@", NSStringFromCGPoint(point));
}

然后,您可以使用SKNode方法containsPoint:将这些坐标与所需节点进行比较,以查看滑动是否来自节点。