gpt4 book ai didi

iphone - 将触摸事件传递给 View Controller 的所有 subview

转载 作者:行者123 更新时间:2023-12-03 19:23:31 25 4
gpt4 key购买 nike

我有一个 View Controller ,它在其上创建多个 subview 。所有 subview 和 View Controller 都接受触摸。如何将触摸点信息传达给屏幕上的所有 subview ?请记住,每个 subview 都会覆盖整个屏幕,因此在添加一些内容后,它有点像书中的页面。也就是说,用户不能直接触摸顶部 subview 下方的任何 subview 。我尝试过使用 [self.nextResponder TouchesBegan:touches withEvent:event] 但这只会将触摸信息从顶部 subview 发送到 super View ,绕过屏幕上的所有其他 subview 。谢谢

最佳答案

我会在所有内容之上放置另一个 subview 。这将获取您感兴趣的所有触摸并将它们传递回 View Controller 。然后,您的 View Controller 将迭代其所有子 UIView,并为它们提供事件。

即类似的东西

for (UIView *view in subviews)
[view touchesBegan:touches withEvent:event];

尽管这是假设您想要将事件传递到的所有 subview 都是 View Controller 的 subview 。

关于iphone - 将触摸事件传递给 View Controller 的所有 subview ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1402614/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com