在哪种方法中,我将一个UIGestureRecognizer添加到我的SKScene.如何检测哪个节点被刷新?这似乎不起作用:
-(id)initWithSize:(CGSize)size { if (self = [super initWithSize:size]) { ... UISwipeGestureRecognizer *recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)]; recognizer.direction = UISwipeGestureRecognizerDirectionUp; [[self view] addGestureRecognizer:recognizer]; } return self; }
解决方法
您可以在此方法中添加UISwipeGestureRecognizer:
- (void)didMoveToView:(SKView *)view { UISwipeGestureRecognizer *recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)]; recognizer.direction = UISwipeGestureRecognizerDirectionUp; [[self view] addGestureRecognizer:recognizer]; }
这就是您如何检测哪个SKNode被刷新:
- (void)handleSwipe:(UISwipeGestureRecognizer *)sender { if (sender.state == UIGestureRecognizerStateEnded) { CGPoint touchLocation = [sender locationInView:sender.view]; touchLocation = [self convertPointFromView:touchLocation]; SKSpriteNode *touchedNode = (SKSpriteNode *)[self nodeAtPoint:touchLocation]; NSLog(@"%@",touchedNode); } }