【问题标题】:Why does location not appear in touchesEnded?为什么位置没有出现在 touchesEnded 中?
【发布时间】:2016-01-26 09:46:25
【问题描述】:

我正在寻找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,但我知道手势识别器独立于触摸工作。知道发生了什么吗?

【问题讨论】:

    标签: location swift2 uigesturerecognizer touchesbegan touchesended


    【解决方案1】:

    设置这两个手势属性:

    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?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-14
      • 1970-01-01
      • 1970-01-01
      • 2011-07-27
      • 2022-01-20
      • 1970-01-01
      • 2011-09-04
      • 2020-04-18
      相关资源
      最近更新 更多