3

UIResponder

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

[event allTouches]和有什么区别[touches allObjects]

4

2 回答 2

6

据我了解,如下:

[event allTouches]返回作为事件一部分的所有触摸。其中一些触摸可能意味着另一个 UIResponder。

例如,您可能同时单击两个视图,并且与每个视图关联的响应者将被事件的所有触摸调用。

[touches allObject]仅包含对此响应者的触动。因此,在大多数情况下,这就是您所追求的。

于 2010-07-22T03:13:06.647 回答
3

该事件允许通过allTouches. 即使是当前未激活的触摸(不移动不开始不结束也不被取消)。

for (UITouch* touch in [[event allTouches]allObjects]) //loops through the list of all the current touches

touches是所有已更改且符合当前事件条件的触摸的列表。

for (UITouch* touch in [touches allObjects]) //loops through the list of all changed touches for this event.

因此对于touchesBegan:withEvent:

  • 如果一根手指触摸屏幕touches[event allTouches]就会有相同的内容。
  • 如果第二根手指触摸屏幕touches,将提供与该手指关联的 UITouch,[event allTouches]并将为该手指和已经触摸屏幕的手指提供 UITouch。
  • 如果另外 2 根手指同时触摸屏幕,touches将为另外 2 根手指提供 UITouch,[event allTouches]并将提供 4 个 UITouch 实例。

现在的情况下touchesEnded:withEvent:

  • 如果抬起一根手指,touches将访问与该手指关联的 UITouch 实例,同时[event allTouches]将提供 4 个 UITouch 实例,甚至是结束触摸之一。
于 2011-12-14T22:48:30.647 回答