【发布时间】:2016-10-02 20:27:40
【问题描述】:
嘿,在尝试跟踪多次触摸时,我收到了这个错误。而且我知道为什么我会因为 touchesbegin 函数顶部的 Set 而得到错误。但我必须将我的 Set 保留在 overrideBegin 中。那么我将如何解决此错误并在不更改原始覆盖值的情况下使此代码无错误。
代码:
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
var touchesArray = touches.allObjects()
var nNumTouches = touchesArray.count
var touch: UITouch!
var ptTouch = CGPoint.zero
for nTouch in 0..<nNumTouches {
touch = touchesArray[nTouch]
ptTouch = touch.locationInView(self.view)
//I need it to print the location of each individual touch like finger 1 or finger 2 is in this location
}
}
【问题讨论】:
-
应该不需要将集合转换为数组,可以遍历集合:
for touch in touches { ... }