6

假设我有两根手指触摸 iPhone 的屏幕,但只有一根手指在移动。

TouchesMoved 将只显示一根手指(事件)。

我怎么知道 TouchesMoved 也指的是两个手指中的哪一个?

4

5 回答 5

1

不幸的是,如果您考虑一下,则没有“确定”的方法可以将一根手指与一个触摸点相关联。毕竟,你的手指并没有 iPhone 能够采样的全球唯一 ID。

您需要做的是记录“先前”位置,这对于管理捏合和其他事情很有用 - 并根据与先前触摸集的接近程度标记每个手指。

于 2009-08-10T16:56:12.943 回答
1

我发现可以做我想做的事。只需在 iTunesU 上查看斯坦福大学的 CS193P 课程。

于 2009-09-10T08:53:11.383 回答
1

首先,在您的UIView

self.multipleTouchEnabled = true

然后保留UITouch对象的字典。相同的UITouch对象被传入touchesBegantouchesMovedtouchesEnded

var touchTypes = Dictionary<UITouch, Int>()

override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
    for touchObject in touches {
        touchTypes.updateValue(i, forKey: touch as UITouch) //determine i for your own implementation
    }
}

override func touchesMoved(touches: NSSet, withEvent event: UIEvent) {
    let type = touchTypes[touch] //depending on this value, do something
}

override func touchesEnded(touches: NSSet, withEvent event: UIEvent) {
    for touchObject in touches {
        touchTypes.removeValueForKey(touchObject as UITouch)
    }
}
于 2014-10-19T00:03:08.700 回答
0

NSSet *您从方法中获取触摸TouchesBegan,您需要遍历所有触摸并将它们放入您的应用程序的上下文中,以便您以后可以识别它们。

如果您描述了您的意图,那么帮助您会容易得多......

于 2009-08-10T17:11:01.573 回答
0

你写了

TouchesMoved 将只显示一根手指(事件)。

但事实并非如此:只要两根手指触摸屏幕,并且其中至少有一个移动,您就会用两根手指touchesMoved得到a 。

如果临时拿起一根手指,您可能会touchesMoved用一根手指接到一些电话,因此您必须决定如何处理。

于 2009-08-11T04:26:33.377 回答