处理触摸

发布于 2024-09-13 07:48:19 字数 253 浏览 4 评论 0原文

我有一个带有多个子视图的 UIView 子类,我想在类中处理这些事件:

  • touchesBegan:withEvent:
  • touchesMoved:withEvent:
  • touchesEnded:withEvent:

但我也希望在子视图中调用这些事件。我怎样才能做到这一点?

(我已经尝试过 hitTest,但我只收到 TouchBegan 事件,并且该方法没有发送任何触摸)

I have a UIView subclass with several subviews and I want to handle these events in the class:

  • touchesBegan:withEvent:
  • touchesMoved:withEvent:
  • touchesEnded:withEvent:

but I also want these event to be called at the subviews. How can I accomplish that?

(I have already tried with hitTest, but I only get the touchesBegan event and no touches are send with the method)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

莫言歌 2024-09-20 07:48:19

我设法通过在主窗口中重写以下方法来解决这个问题:

- (void)sendEvent:(UIEvent*)anEvent

来检查它是否是正确的事件

if ([[[anEvent allTouches] anyObject] phase] == UITouchPhaseBegan)

我还通过对 UITouchPhaseMoved 和 UITouchPhaseEnded 执行相同的操作 ,执行我的自定义代码,然后发送 [super sendEvent:anEvent];

I have managed to solve it by overriding the following method at the main window:

- (void)sendEvent:(UIEvent*)anEvent

I also check if it is the right event with through

if ([[[anEvent allTouches] anyObject] phase] == UITouchPhaseBegan)

I do the same for UITouchPhaseMoved and UITouchPhaseEnded, execute my custom code and then send [super sendEvent:anEvent];

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