仅在超级视图上禁用触摸事件?

发布于 2024-11-28 15:50:29 字数 106 浏览 4 评论 0原文

我的屏幕上有一个从 XIB 加载的子视图,我需要在其超级视图上禁用触摸事件,同时最终不触摸子视图。我该怎么做? 另外,我正在使用 iOS。

谢谢!

I have a subview on the screen that is loaded from a XIB, I need to disable touch events ONLY on its superview while not touching the subview in the end. How would I do this?
Also, I am using iOS.

Thanks!

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

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

发布评论

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

评论(3

明明#如月 2024-12-05 15:50:29

这就是您可以执行此操作的方法 -

  1. 转到界面生成器和界面生成器。选择您的超级视图(您要为其禁用触摸)。
  2. 打开右侧导航栏。底部有一个名为“用户交互已启用”的检查字段。您可以取消标记。当然,您也可以通过代码来完成此操作。但这更加形象化。此屏幕截图可能会有所帮助。查看图像底部...

在此处输入图像描述

This is how you can go about doing this -

  1. Go to interface builder & select your superview (for which you want to disable touches).
  2. Open right navigation bar. At the bottom there is a checkfield called "User Interaction Enabled". You can unmark it. Of course you can go about doing this from code too. But this is more graphic. This screenshot might help. See bottom of the image...

enter image description here

挽容 2024-12-05 15:50:29

我也是 iPhone 开发新手,但是当我尝试仅移动 UIImage 视图时,这段代码帮助了我。

如果您在视图中使用按钮或标签,则可以对此代码应用更改。

if ([touch.view isKindOfClass:[UIImageView class]])

{
    imageDemo.center = touchLocation;
}

I am also new to iphone development but htis piece of code helped me out when i tried to move only UIImage view.

you can apply cahnges on this code if you are using buttons or labels in your view.

if ([touch.view isKindOfClass:[UIImageView class]])

{
    imageDemo.center = touchLocation;
}
你在我安 2024-12-05 15:50:29

在 XIB 中,您可以只使用同一级别的超级视图并将其 usertouch 界面设置为 FALSE,而不是使用所有其他视图作为子视图。

In XIB, rather than using all other views as subview, u can just use superview at same level and set its usertouch interface as FALSE.

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