大家好,所以当我使用它们时,我的GestureReconizers会崩溃我的应用程序。我收到一个错误,说它收到了一个无法识别的手势,我也收到了SIGABRT错误。我试过看其他帖子,但还没有解决。 [顺便说一句,这是在我的didMoveToView部分]
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时才有效。所以,如果你知道一个很好的方法,那就太棒了。
答案 0 :(得分:2)
你应该使用冒号“:
”来处理Swipes而不是半冒号“;
”
这就是您的代码崩溃的原因
这是您的固定代码
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")
}
}
输出
答案 1 :(得分:1)
你不应该在选择器上使用分号,
此"handleSwipes:"
应为{{1}}