透明视图上的 UITapGestureRecognizer

发布于 2024-11-07 12:48:05 字数 363 浏览 0 评论 0原文

我有一个带有视图的树,其中最高级别的视图是透明的,并且包含图像或标签(具有透明背景)。

将 UITapGestureRecognizer 附加到此视图时,我只会收到有关包含图像的视图的通知。
此外,如果我将视图留空,则仅当背景颜色与 [UIColor clearColor] 不同时我才会收到事件。

我已经完成了转储,整个视图树都有 userInteractionEnable = YES。

如何让 UITapGesturerRecognizer 在透明背景的视图上工作?

已解决
问题不是我想的那样。透明视图位于滚动视图中,并且在初始化期间它们位于视图的可见区域之外。那些在可见区域内的工作正常。

I have a tree with views where the highest level view is transparent and contains either an image or a label (with a transparent background).

When attaching a UITapGestureRecognizer to this view, I only get notifications on the views which contain images.
Also, if I leave the view empty, then I get events only when the background color is different than [UIColor clearColor].

I have done a dump and the entire view tree has userInteractionEnable = YES.

How can I get the UITapGesturerRecognizer to work on the view with a transparent background?

Solved
Problem was not what I thought. The transparent views were in a scroll view and during initialization they were outside of the view's visible area. Those within the visible area work ok.

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

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

发布评论

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

评论(3

始终不够 2024-11-14 12:48:06

这里可以大胆猜测,但如果您在视图中包含 1x1 像素图像,那么该视图是否符合手势条件?
另一个同样疯狂的猜测是向视图添加透明图像并尝试。

Wild guesses here, but if you include a 1x1 pixel image in the view, would that view then qualify for gestures?
Another equally wild guess would be to add a transparent image to the view and try that.

温暖的光 2024-11-14 12:48:06

尝试为视图提供近乎透明的背景颜色,例如 [UIColor colorWithWhite:0 alpha:0.01]

Try giving the view a nearly-transparent background color, like [UIColor colorWithWhite:0 alpha:0.01].

沧桑㈠ 2024-11-14 12:48:06

尝试将背景颜色设置为除clearColor之外的任何颜色并将alpha属性设置为0.0;

myView.backgroundColor = [UIColor blackColor];
myView.alpha = 0.0;

Try setting the background color to whatever except the clearColor and setting the alpha property to 0.0;

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