Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 从例子中困惑_Ios_Cocoa Touch - Fatal编程技术网

Ios 从例子中困惑

Ios 从例子中困惑,ios,cocoa-touch,Ios,Cocoa Touch,我看到了一些touches使用的示例: for (UITouch *touch in touches) {...} 而其他人则使用: UITouch *touch = [touches anyObject]; 我不明白什么时候需要for循环和not循环。有人能帮我理解这一点吗?对于回路,您可以使用多点触摸 对于回路,您可以使用多点触摸 如果您关心多点触控情况下的每个单独触控,请在触控集合中循环-即,如果您需要知道任何触控是否击中特定位置: for (UITouch *touch in tou

我看到了一些touches使用的示例:

for (UITouch *touch in touches) {...}
而其他人则使用:

UITouch *touch = [touches anyObject];

我不明白什么时候需要for循环和not循环。有人能帮我理解这一点吗?

对于回路,您可以使用多点触摸

对于回路,您可以使用多点触摸

如果您关心多点触控情况下的每个单独触控,请在触控集合中循环-即,如果您需要知道任何触控是否击中特定位置:

for (UITouch *touch in touches) {...}

如果您只关心触摸是否发生,或者不支持多点触摸,那么
[触摸任何对象]
方法就可以了。

如果您关心多点触摸情况下的每个单独触摸,请循环触摸集合-即,如果您需要知道任何触摸是否击中特定位置:

for (UITouch *touch in touches) {...}

如果您只关心触摸是否发生,或者不支持多点触摸,那么
[触摸任何对象]
方法就可以了。

如果您没有启用多点触摸,那么您将收到单点触摸。您可以使用
[触摸任何对象]从集合
触摸
(包含单个项目)中检索它

如果启用了多点触控,则集合
触控
可能包含多个项目,您必须使用循环访问所有项目

for (UITouch *touch in touches) {
    // Your code here to handle the touch
}

最后,请注意,即使您只有一次触摸,使用循环也可以在所有情况下工作。

如果您没有启用多点触摸,则您将收到一次触摸。您可以使用
[触摸任何对象]从集合
触摸
(包含单个项目)中检索它

如果启用了多点触控,则集合
触控
可能包含多个项目,您必须使用循环访问所有项目

for (UITouch *touch in touches) {
    // Your code here to handle the touch
}
最后,请注意,即使只有一次触摸,使用循环也可以在所有情况下工作