[event allTouches] 和 [touches allObjects] 之间的区别?

发布于 2024-09-11 01:49:41 字数 211 浏览 4 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

深白境迁sunset 2024-09-18 01:49:41

据我理解,如下:

[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.

深海少女心 2024-09-18 01:49:41

该事件通过 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]< /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).

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

touches is the list of all the touches that have changed and are eligible for the current event.

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

So for touchesBegan:withEvent:

  • If one finger touches the screen touches and [event allTouches] will have the same content.
  • If a second finger touches the screen 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.
  • If 2 additional fingers touch the screen at the "same" time 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:

  • If one finger is lifted, 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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文