如何将一个滑动手势添加到spritekit中的节点

我试图添加一个滑动手势到一个节点,以便当用户滑动它,它会离开屏幕,但我不断收到一个SIGABRT错误:

 `Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[fidget2.PlankScene swipedRight:]: unrecognized selector sent to instance 0x7ff4c3603e00'` 

我不知道为什么这个错误是popup。 我确保节点在.sks文件中正确标记。 这是我的代码:

 import SpriteKit let plankName = "woodPlank" class PlankScene: SKScene { var plankWood : SKSpriteNode? override func didMove(to view: SKView) { plankWood = childNode(withName: "woodPlank") as? SKSpriteNode let swipeRight : UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: Selector("swipedRight:")) swipeRight.direction = .right view.addGestureRecognizer(swipeRight) } func swipedRight(sender: UISwipeGestureRecognizer) { print("Object has been swiped") } func touchesMoved(touches: Set<NSObject>, withEvent event: UIEvent) { let touch = touches.first as! UITouch let location = touch.location(in: self) if (plankWood?.frame.contains(location))! { print("Swipe has started") } } } 

有同样的问题,所以我们有一个接受的答案,我想指出0x141E留下的评论是正确的解决scheme:

#selector(PlankScene.swipedRight)replaceSelector("swipedRight:") #selector(PlankScene.swipedRight)