在 Swift 中以 CGPoint 的形式跟踪多个触摸



所以这已经困扰了我一段时间。我想在iPhone上同时跟踪游戏的多个触摸,将它们存储为CGPoint并实时分析它们的动作(可能在touchesMove功能中)以在游戏中执行操作。

我已经阅读了一些解决方案,但我无法根据我的确切需求修改它们。这两篇文章中的答案可能走在正确的轨道上:

精灵套件中的多点触控手势

在 Swift 中获取多个触摸的坐标

我对一些实现有自己的想法,但它们似乎不起作用,我希望看到更多的想法。任何帮助和建议将不胜感激。必须通过这个障碍!

尝试这样的事情:

class CustomView: UIView {
   override func touchesMoved(touches: NSSet, withEvent event: UIEvent) {
      let touchArray = touches.allObjects as [UITouch]
      println("-----")
      println("(touchArray.count) touches:")
      for touch in touchArray{
         println(touch.locationInView(self))
      }
   }
}

最新更新