ios中的每个触摸点是否有指针?

我一直在研究,无法find每个触摸点在ios中是否有唯一的标识符。 我也想知道如何快速访问,但无法find任何文件。

不是每个点,而是每个触摸。 要访问它们,需要自己的触摸处理,例如触摸发生的UIView或其ViewController。 这只需要你为touchesBegan:withEvent:编写你自己的方法touchesBegan:withEvent:touchesMoved:withEvent:touchesEnded:withEvent:

touchesBegan:withEvent:touchesMoved:withEvent:touchesEnded:withEvent:由iOS调用时,他们在NSSet报告触摸。 该集合的每个成员都是触摸数据结构的唯一指针,如果要随时间过滤触摸,则应该将它们用作NSMutableDictionary的键。

就像触摸开始,当你第一次碰到触摸:

 var pointDict: [String?: NSObject?] = [:] ... func touchesBegan(touches: NSSet, withEvent event: UIEvent) { // Regular multitouch handling. for touch in touches.allObjects as UITouch { // Create a new key from the UITouch pointer: let key = \(touch) // Put the point into the dictionary as an NSValue pointDict.setValue(NSValue(CGPoint: touch.locationInView(myView)), forKey:key) } } 

现在在touchesMoved你需要检查指针对存储的键:

 func touchesMoved(touches: NSSet, withEvent event: UIEvent) { for touch in touches.allObjects as UITouch { // Create a new key from the UITouch pointer: let key = \(touch) // See if the key has been used already: let oldPoint = pointDict[key] if oldPoint != nil { (do whatever is needed to continue the point sequence here) } } } 

如果已经有一个使用相同的touchID作为其键的条目,则会获取该键的存储对象。 如果之前的触摸没有使用该ID,那么当您向对应的对象请求时,字典将返回零。

现在,您可以将自己的指针指定给这些触点,并知道它们都属于同一个触摸事件。