为什么 location 没有出现在 touchesEnded 中?
Why does location not appear in touchesEnded?
我正在寻找 touchesEnded
的最终位置。我的 touchesBegan
代码如下所示:
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
if let touch = touches.first {
touchStart = touch.locationInNode(self)
print("touchStart_1: \(touchStart)")
}
}
印刷品告诉我位置。
在touchesEnded
中,我有以下内容:
override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
if let touch = touches.first, start = touchStart {
print("touchStart_2: \(touchStart)")
let location = touch.locationInNode(self)
print("touchEnded: \(location)")
}
}
这些都不会打印 returns 任何东西。作为附加信息,我也在其他地方使用 UISwipeGestureRecognizer
,但我知道手势识别器的工作独立于触摸。知道发生了什么事吗?
设置这 2 个手势属性:
let swipeGesturte: UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: "swipeAction:")
swipeGesturte.direction = UISwipeGestureRecognizerDirection.Right
swipeGesturte.cancelsTouchesInView = false // 1.
swipeGesturte.delaysTouchesEnded = false // 2.
self.view.addGestureRecognizer(swipeGesturte)
有关 cancelsTouchesInView 的更多信息:What really happens when call setCancelsTouchesInView?
我正在寻找 touchesEnded
的最终位置。我的 touchesBegan
代码如下所示:
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
if let touch = touches.first {
touchStart = touch.locationInNode(self)
print("touchStart_1: \(touchStart)")
}
}
印刷品告诉我位置。
在touchesEnded
中,我有以下内容:
override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
if let touch = touches.first, start = touchStart {
print("touchStart_2: \(touchStart)")
let location = touch.locationInNode(self)
print("touchEnded: \(location)")
}
}
这些都不会打印 returns 任何东西。作为附加信息,我也在其他地方使用 UISwipeGestureRecognizer
,但我知道手势识别器的工作独立于触摸。知道发生了什么事吗?
设置这 2 个手势属性:
let swipeGesturte: UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: "swipeAction:")
swipeGesturte.direction = UISwipeGestureRecognizerDirection.Right
swipeGesturte.cancelsTouchesInView = false // 1.
swipeGesturte.delaysTouchesEnded = false // 2.
self.view.addGestureRecognizer(swipeGesturte)
有关 cancelsTouchesInView 的更多信息:What really happens when call setCancelsTouchesInView?