我看到了一些使用 touchesBegan 回调的例子:
for (UITouch *touch in touches) {...}
而其他人使用:
UITouch *touch = [touches anyObject];
我不明白什么时候需要 for 循环,什么时候不需要。有人可以帮助我理解这一点吗?
最佳答案
如果您没有启用多点触控,那么您将接收到单点触控。您可以使用 [touches anyObject];
从集合 touches
(包含单个项目)中检索它。
如果您启用了多点触控,那么集合touches
可能包含多个项目,您必须使用一个循环来访问所有这些项目。
for (UITouch *touch in touches) {
// Your code here to handle the touch
}
最后,请注意,即使您只有一次触摸,使用循环在所有情况下都有效。
关于ios - 对 touchBegan 示例感到困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9752428/