UISwipeGesture'无法识别的select器发送到实例'

如果有人可以请帮我解决这个问题,将是伟大的! 我花了几个小时试图修复,没有运气

错误…

2016-06-23 20:30:43.341057缩放环[408:38903] [DYMTLInitPlatform]平台初始化成功2016-06-23 20:30:43.750822缩放环[408:38776]启用金属GPU帧捕捉2016-06-23 20:30:43.751531缩放环[408:38776]金属APIvalidation已启用2016-06-23 20:30:48.293661缩放环[408:38776] – [Scaling_Rings.MenuScene slide:]:无法识别的select器发送到实例0x145e1c410 2016- 06-23 20:30:48.299061缩放环[408:38776] *由于未捕获exception'NSInvalidArgumentException',原因:' – [Scaling_Rings.MenuScene slide:]:无法识别的select器发送到实例0x145e1c410'*第一个抛出调用堆栈:(0x190ad9980 0x1900d44bc 0x190ae0778 0x190add6e0 0x1909de61c 0x196e13754 0x196e16e5c 0x1969f6b3c 0x196894900 0x196e0747c 0x196e07100 0x196e06338 0x196892a24 0x1968638c8 0x19701efd4 0x19701941c 0x190a8a3f0 0x190a89cc8 0x190a87938 0x1909ba2e4 0x19239315c 0x1968ce6fc 0x1968c9438 0x1000a1d44 0x19055c600)的libc ++ abi.dylib:与uncaug终止 htexceptiontypesNSException(lldb)

码…

import Foundation import SpriteKit var startRing = SKShapeNode() class MenuScene: SKScene { func slide(sender: AnyObject){ debugPrint("WORKS") } override func didMove(to view: SKView) { let upSwipe = UISwipeGestureRecognizer(target: self, action: Selector("slide:")) upSwipe.direction = .up view.addGestureRecognizer(upSwipe) } } 

您需要将select器声明更改为#selector(slide)select器#selector(slide)并在方法参数func slide(_ sender: UISwipeGestureRecognizer)之前添加下划线:

 class GameScene: SKScene { func slide(_ sender: UISwipeGestureRecognizer){ print("WORKS") } override func didMove(to view: SKView) { let upSwipe = UISwipeGestureRecognizer(target: self, action: #selector(slide)) upSwipe.direction = .up view.addGestureRecognizer(upSwipe) } }