There is no easy way to do it, but one way I can think of would be to add a sub SKView to your SKScene and place an UIImageView as the only thing inside that SKView. Then you can add a gesture recognizer like normal to the SKView.
Here's an example of what I'm talking about:
UIImageView *button = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ButtonSprite"]];
SKView *spriteNodeButtonView = [[SKView alloc] initWithFrame:CGRectMake(100, 100, button.frame.size.width, button.frame.size.height)];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(someMethod:)];
[spriteNodeButtonView addGestureRecognizer:tap];
[spriteNodeButtonView addSubview:button];
You can put the SKView wherever you want and use any of the gesture recognizers on an SKView: UITapGestureRecognizer
, UILongPressGestureRecognizer
, UISwipeGestureRecognizer
, UIPinchGestureRecognizer
, UIRotationGestureRecognizer
, UIPanGestureRecognizer
, or UIScreenEdgePanGestureRecognizer
.
Then for your method implementation do something like this:
-(void)someMethod:(UITapGestureRecognizer *)recognizer {
CGPoint touchLoc = [recognizer locationInView:self.view];
NSLog(@"You tapped the button at - x: %f y: %f", touchLoc.x, touchLoc.y);
}