在UIResponder
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
[event allTouches]
和有什么区别[touches allObjects]
?
在UIResponder
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
[event allTouches]
和有什么区别[touches allObjects]
?
据我了解,如下:
[event allTouches]
返回作为事件一部分的所有触摸。其中一些触摸可能意味着另一个 UIResponder。
例如,您可能同时单击两个视图,并且与每个视图关联的响应者将被事件的所有触摸调用。
[touches allObject]
仅包含对此响应者的触动。因此,在大多数情况下,这就是您所追求的。
该事件允许通过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。touches
将为另外 2 根手指提供 UITouch,[event allTouches]
并将提供 4 个 UITouch 实例。现在的情况下touchesEnded:withEvent:
touches
将访问与该手指关联的 UITouch 实例,同时[event allTouches]
将提供 4 个 UITouch 实例,甚至是结束触摸之一。