为什么位置没有出现在touchesEnded中?

时间:2016-01-26 09:46:25

标签: location swift2 uigesturerecognizer touchesbegan 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)")
  }
}

这些印刷品都不会返回任何内容。作为附加信息,我也在其他地方使用UISwipeGestureRecognizer,但据我所知,手势识别器的工作与触摸无关。知道了什么?

1 个答案:

答案 0 :(得分:0)

设置此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?