如何使 UIScrollView 将触摸转发到 UIView 子类子视图?

发布于 2024-12-23 09:12:32 字数 596 浏览 0 评论 0原文

我有一个 UIScrollView,我将其用作两个“页面”视图的容器。第一页包含两个子视图:一种用户可以通过触摸在其上绘画的“画布”UIView 子类,以及一个充满 UIControl 的“控制面板”UIView 子类。滚动视图本身已禁用滚动(我正在使用 UIPageControl 来滚动它。)

问题是这样的:当我点击控制面板视图中的任何控件时,它们工作正常。但是,当我触摸画布视图时,什么也没有发生。画布子视图上没有控件;它只是一个空的 UIView 子类,用于检测触摸并在用户手指下绘制点。 (以前这一切都工作正常;我最近刚刚将这两部分放入滚动视图中。)

如何告诉 UIScrollView 将触摸转发到画布子视图?我已设置滚动视图,以便关闭“延迟内容触摸”和“可取消内容触摸”。 “用户交互已启用”和“多点触控”均已打开。

我不知道是否要子类化 UIScrollView 并更改其触摸处理,或者是否要重写画布 UIView 子类中的某些其他方法。

编辑:Vince(评论者)提示我查看触摸事件处理程序所在的位置。它们存在于 UIViewController 子类中,该子类拥有控制面板视图和画布视图(现在还有滚动视图)。touchesBegan 不再被调用。

谢谢

I have a UIScrollView which I'm using as a container for two 'pages' of views. The first page contains two subviews: a kind of 'canvas' UIView subclass that the user can paint on with touches, and a 'control panel' UIView subclass full of UIControls. The scroll view itself has scrolling disabled (I'm using a UIPageControl to scroll it.)

The problem is this: when I tap on any of the controls in the control panel view they work fine. However, when I touch the canvas view, nothing happens. There are no controls on the canvas subview; it's just an empty UIView subclass that detects touches and draws points under the user's finger. (Previously this was all working fine; I've just recently put the two pieces in the scroll view.)

How can I tell the UIScrollView to forward touches to the canvas subview? I have set the scrollview so that Delays Content Touches and Cancellable Content Touches are off. User Interaction Enabled and Multiple Touch are both on.

I do not know whether to subclass the UIScrollView and change it's touch handling, or whether to override some other method in the canvas UIView subclass.

EDIT: Vince (commenter) prompted me to look at where the touch event handlers lived. They exist in the UIViewController subclass which owns the control panel view and the canvas view (and, now, the scroll view.) touchesBegan isn't being called anymore.

Thanks

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

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

发布评论

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

评论(1

_失温 2024-12-30 09:12:32

您使用的是 iOS 5 吗?如果是这样,请尝试使用 UIViewController Container API。如果您的 ViewController 下有 UIScrollView 和“子”视图控制器,则可能会出现链接问题。尝试在控制器中调用 [self addChildViewController:theCanvasVC] 来获取滚动视图。

我猜测你的架构,所以我可能会离开。让我知道您的应用程序是如何组织的。

您可以在此处阅读容器视图控制器< /a>.向下滚动到“实现容器视图控制器”。

Are you using iOS 5? If so, try making use of the UIViewController Container APIs. If you have a ViewController with the UIScrollView and "child" view controller under it, you may linking issues. Try calling [self addChildViewController:theCanvasVC] in your controller for the scrollView.

I'm guessing at your architecture so i may be off. Let me know how your app is organized.

You can read up on Container View Controllers here. Scroll down to "Implementing a Container View Controller".

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