Swift UIGestureReconizer崩溃-无法识别的手势错误
嗨,我的手势识别器在我使用时会使我的应用程序崩溃。我收到一个错误,说它收到了一个无法识别的手势,我也收到了一个SIGABRT错误。我试过看其他帖子,但还没有找到解决办法。 [顺便说一句,这是我的didMoveToView部分]Swift UIGestureReconizer崩溃-无法识别的手势错误,swift,sprite-kit,swipe,Swift,Sprite Kit,Swipe,嗨,我的手势识别器在我使用时会使我的应用程序崩溃。我收到一个错误,说它收到了一个无法识别的手势,我也收到了一个SIGABRT错误。我试过看其他帖子,但还没有找到解决办法。 [顺便说一句,这是我的didMoveToView部分] var upSwipe = UISwipeGestureRecognizer(target: self, action: Selector("handleSwipes;")) var downSwipe = UISwipeGestureRecognizer(target:
var upSwipe = UISwipeGestureRecognizer(target: self, action: Selector("handleSwipes;"))
var downSwipe = UISwipeGestureRecognizer(target: self, action: Selector("handleSwipes;"))
var rightSwipe = UISwipeGestureRecognizer(target: self, action: Selector("handleSwipes;"))
var leftSwipe = UISwipeGestureRecognizer(target: self, action: Selector("handleSwipes;"))
upSwipe.direction = .Up
downSwipe.direction = .Down
rightSwipe.direction = .Right
leftSwipe.direction = .Left
view.addGestureRecognizer(upSwipe)
view.addGestureRecognizer(downSwipe)
view.addGestureRecognizer(leftSwipe)
view.addGestureRecognizer(rightSwipe)
func handleSwipes(sender: UISwipeGestureRecognizer) {
if sender.direction == .Left {
msgText("Left")
}
if sender.direction == .Right {
msgText("Right")
}
if sender.direction == .Up {
msgText("Up")
}
if sender.direction == .Down {
msgText("Down")
}
}
我还尝试仅在map.zPosition==100时激活手势。所以如果你知道一个好方法,那就太棒了。你不应该在选择器上使用分号
此
“Handlesweeps;”“
应为“Handlesweeps:”
您不应在选择器上使用分号
此“Handlesweeps;”
应为“Handlesweeps:
您应使用冒号“:
”进行把手滑动,而不是分号“;
”
这就是你的代码崩溃的原因
这是你的固定密码
输出
您应该使用冒号“:
”来进行手柄滑动,而不是分号“;
”
这就是你的代码崩溃的原因
这是你的固定密码
输出
尝试选择器(“Handlesweeps”)而不是选择器(“Handlesweeps;”)等。尝试选择器(“Handlesweeps”)而不是选择器(“Handlesweeps;”)等。此外,您可以摆脱
选择器()
,只需使用“Handlesweeps:
作为选择器。“Handlesweeps”???这里没有其他参数。。。所以:不应该存在,对吗?@user3441734uisweegestureerecognizer
是参数,所以您可以去掉Selector()
,只需使用“handlesweeps:
作为选择器。“handlesweeps”???这里没有其他参数。。。所以:不应该在那里,对吗?@user3441734uisweegestureerecognizer
是参数
override func viewDidLoad() {
super.viewDidLoad()
var upSwipe = UISwipeGestureRecognizer(target: self, action: Selector("handleSwipes:"))
var downSwipe = UISwipeGestureRecognizer(target: self, action: Selector("handleSwipes:"))
var leftSwipe = UISwipeGestureRecognizer(target: self, action: Selector("handleSwipes:"))
var rightSwipe = UISwipeGestureRecognizer(target: self, action: Selector("handleSwipes:"))
leftSwipe.direction = .Left
rightSwipe.direction = .Right
upSwipe.direction = .Up
downSwipe.direction = .Down
view.addGestureRecognizer(leftSwipe)
view.addGestureRecognizer(rightSwipe)
view.addGestureRecognizer(upSwipe)
view.addGestureRecognizer(downSwipe)
}
func handleSwipes(sender:UISwipeGestureRecognizer) {
if (sender.direction == .Left) {
print("Swipe Left")
}
if (sender.direction == .Right) {
print("Swipe Right")
}
if (sender.direction == .Up) {
print("Swipe Up")
}
if (sender.direction == .Down) {
print("Swipe Down")
}
}