为什么我的窗口子视图显示,但不处理任何触摸?

发布于 2024-10-12 07:35:01 字数 700 浏览 5 评论 0原文

我的 UIWindow 在 Interface Builder 中的结构为:

  • window
    • drawingView(自定义 UIView)
    • 工具栏(UIToolbar)

其中drawingView使用touchesBegan等处理触摸。但是,当我尝试添加“someView”(自定义UIView),其上有UIButtons作为窗口的子视图时,按钮不接受任何触摸。

我用以下内容创建“someView”:

[[[UIApplication sharedApplication] keyWindow] addSubview:someView]; 

“someView”在绘图视图顶部显示良好,但触摸似乎根本没有注册,并传递到绘图视图。这是为什么?

另一个奇怪的事情是,someView 的背景颜色似乎总是很清晰,即使我以编程方式或在 IB 中将其设置为其他内容。

另外,当我使用它创建 someView 时,

[[UIPopoverController alloc] initWithContentViewController:someView];

它工作正常,可以处理触摸等。我想将其添加为子视图的原因是因为我想要一种更通用的添加 someView 的方法,这也适用于 iphone。

I have my UIWindow structured in Interface Builder as:

  • window
    • drawingView (custom UIView)
    • toolbar (UIToolbar)

Where the drawingView handles touches using touchesBegan etc. However, when I try and add 'someView' (a custom UIView) which has UIButtons on it as a subview of window, the buttons don't receive any of the touches.

I create 'someView' with:

[[[UIApplication sharedApplication] keyWindow] addSubview:someView]; 

'someView' displays fine on top of the drawingView, but the touches don't seem to register at all, and get passed through to drawingView. Why is that?

Another odd thing is that the backgroundColor of someView always seems to be clear, even if I set it to something else programatically or in IB.

Also, when I create someView using

[[UIPopoverController alloc] initWithContentViewController:someView];

it works fine, handling touches and all. The reason I want to add it as a subview is because I want a more general way of adding someView, that is works on the iphone as well.

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

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

发布评论

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

评论(2

缪败 2024-10-19 07:35:01

确保在需要接收触摸的视图的所有父级上设置了 userInteractionEnabled 标志。

Make sure the userInteractionEnabled flag is set on all parents of the view that needs to receive touches.

玩物 2024-10-19 07:35:01

我已经找到了解决办法(以一种黑客的方式)。

我必须添加“someView”作为drawView的子视图,它在显示时出现在drawView的顶部,并允许我以编程方式使用UIButtons设置someView,它接收触摸。

我认为这是因为drawView是一个OpenGL视图,它覆盖了layerClass,它对视图如何排列以获得触摸做了一些有趣的事情。我认为。

I've figured out a fix (in a hackish kind of way).

I had to add 'someView' as a subview of drawingView, which appears on top of drawView when shown, and allows me to programatically set up someView with UIButtons, which receives touches.

I think it's because drawView is an OpenGL view, that overrides layerClass which does something funky with how the views are arranged to obtain touches. I think.

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