[event allTouches] 和 [touches allObjects] 之间的区别?
在 UIResponder
中,
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
[event allTouches]
和 [touches allObjects]
有什么区别?
In UIResponder
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
What's the difference between [event allTouches]
and [touches allObjects]
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据我理解,如下:
[event allTouches]
返回属于事件一部分的所有触摸。其中一些触摸可能是针对另一个 UIResponder 的。例如,您可能同时单击两个视图,并且与每个视图关联的响应者将被事件的所有触摸调用。
[touches allObject]
仅包含此响应者的触摸。因此,在大多数情况下,这就是您所追求的。To my understanding it is as follows:
[event allTouches]
returns all touches that are part of the event. Some of those touches might be meant for another UIResponder.For instance you might click in two view at the same time and the responder associated with each view will get called with all the touches of the event.
[touches allObject]
only contains touches ment for this responder. And is thus in most cases what you are after.该事件通过
allTouches
提供对所有触摸的访问。即使触摸当前不活动(不移动、不开始、不结束、不被取消)。touches
是所有已更改且符合当前事件条件的触摸的列表。因此对于
touchesBegan:withEvent:
touches
和[event allTouches]
将具有相同的内容。touches
将提供与该手指关联的 UITouch,并且[event allTouches]
将提供该手指和已经触摸屏幕的手指的 UITouch。touches
将为另外 2 个手指提供 UITouch,并且[event allTouches]
将提供 4 个 UITouch 实例。现在,在
touchesEnded:withEvent:
的情况下,touches
将授予对与该手指关联的 UITouch 实例的访问权限,同时[event allTouches]< /code> 将提供 4 个 UITouch 实例,甚至是结束触摸之一。
The event gives access to all the touches through
allTouches
. Even the touches currently not active (not moving not starting not ending and not being canceled).touches
is the list of all the touches that have changed and are eligible for the current event.So for
touchesBegan:withEvent:
touches
and[event allTouches]
will have the same content.touches
will provide the UITouch associated with this finger and[event allTouches]
will provide the UITouch for this finger and the one already touching the screen.touches
will provide the UITouch for the 2 additional fingers and[event allTouches]
will provide the 4 UITouch instances.Now in the case of
touchesEnded:withEvent:
touches
will give access to the UITouch instance associated with that finger while[event allTouches]
will provide the 4 UITouch instances, even the one of the ending touch.