我尝试使用以下代码将 UI 手势识别器添加到 Swift 中的 SKScene
let recognizer = UISwipeGestureRecognizer(target: self, action: "handleSwipe:")
recognizer.direction = UISwipeGestureRecognizerDirection.Right
self.view?.addGestureRecognizer(recognizer)
func handleSwipe() {
println("Swiped Right")
但是,一旦我运行并执行滑动,应用程序就会崩溃并显示以下日志:
2014-11-22 23:21:35.251 Revolution[83866:460316] -[Revolution.levelSelect handleSwipe:]:无法识别的选择器发送到实例 0x7feec842b920 2014-11-22 23:21:35.255 Revolution[83866:460316] *** 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[Revolution.levelSelect handleSwipe:]:无法识别的选择器发送到实例 0x7feec842b920”
libc++abi.dylib:以 NSException 类型的未捕获异常终止
有什么我需要添加到 GameViewController 中或者选择器导致它崩溃的原因吗?
最佳答案
“handleSwipe:”中的“:”表示方法 handleSwipe
接受一个参数。在这种情况下,手势对象被传递给手势处理程序。所以,你的函数应该是
func handleSwipe(gesture:UISwipeGestureRecognizer) {
println("Swiped Right")
}
关于swift - UIGesture 识别器使应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27085593/