ScrollView 位于可见视图之外

发布于 2024-10-27 10:04:37 字数 228 浏览 0 评论 0原文

我尝试创建类似于 iOS4 中的任务菜单的内容:

(抱歉,无法发布足够的代表图像)

我在该视图上有正常的 ViewController,我在 menuView 中添加了子视图。我将 menuViews Y 设置为 -95,这样我就可以将 viewControllers 视图向下移动 95 以显示菜单。但是如果 menuViews Y 为负,我的 menuView 中的滚动视图将不起作用。

I try to create something similar to the task-menu in iOS4:

(Sorry cant post images not enough Rep)

I have normal ViewController on thats view i addSubview of my menuView. I set menuViews Y to -95 so i can just move the viewControllers view 95 Down to Display the menu. But the scrollView in my menuView doesn't work if the menuViews Y is Negative.

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

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

发布评论

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

评论(1

冷夜 2024-11-03 10:04:37

您的滚动视图不会接收触摸输入,因为它超出了其超级视图(您提到的主 ViewController 的视图)的范围。触摸交互系统的工作方式是 AppKit 框架沿着视图层次结构向下测试每个视图和子视图,并使用 - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event 函数。如果视图向此函数返回 YES,它将对其所有子视图重新启动该过程,直到找到仍返回 YES 的最低子视图。您的设置的问题是 Scrollview 的超级视图将返回 NO,因为触摸位于其上方,并且您的 menuView 甚至从未经过测试。因此,您有两种可能的解决方案:

  1. 将 ViewControllers 视图实现为 UIView 的子类(如果还不是),并重载 pointInside:withEvent: 函数,以在触摸位于其框架内或位于menuView 的边界(ViewControllers 框架减去 menuView 的框架)。

  2. 第二种解决方案是简单地将 menuView 放在其超级视图的原点 (0,0) 处,并将 ViewControllers 视图也保留在 (0,0) 处。

我建议使用第二种,因为它不那么复杂,而且更切题。

Your scrollview doesn't receive the touch input because it is outside the bounds of the its superview (the view of the main ViewController you mentioned). The way the touch interaction system works is the AppKit framework goes down the view hierarchy testing each view and subview with the - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event function. If a view returns YES to this function, it will start the process all over again with all of its subviews until it finds the lowest subview that still returns YES. The problem with your setup is that the superview of Scrollview is going to return NO because the touch is above it and your menuView never even gets tested. So you have two possible solutions:

  1. Implement your ViewControllers view as a subclass of UIView (if it is not already) and overload the pointInside:withEvent: function to return YES if the touch is within it's frame OR if it is within the bounds of menuView (ViewControllers frame minus the frame of menuView).

  2. The second solution would be to simply put menuView at the origin of its superview (0,0) and leave the ViewControllers view at (0,0) as well.

I suggest the second as it is less convoluted and more to the point.

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