gpt4 book ai didi

swift - UIGestureReconizer 崩溃 - 无法识别的手势错误

转载 作者:行者123 更新时间:2023-11-28 11:11:53 25 4
gpt4 key购买 nike

您好,当我使用 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 时才激活手势。因此,如果您知道一个好的方法,那就太棒了。

最佳答案

您应该使用冒号“:”来处理滑动而不是分号“;

这就是你的代码崩溃的原因

Here is your fixed code

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")
}
}

Output

ouput

关于swift - UIGestureReconizer 崩溃 - 无法识别的手势错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34472991/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com