透明视图上的 UITapGestureRecognizer
我有一个带有视图的树,其中最高级别的视图是透明的,并且包含图像或标签(具有透明背景)。
将 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这里可以大胆猜测,但如果您在视图中包含 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.
尝试为视图提供近乎透明的背景颜色,例如
[UIColor colorWithWhite:0 alpha:0.01]
。Try giving the view a nearly-transparent background color, like
[UIColor colorWithWhite:0 alpha:0.01]
.尝试将背景颜色设置为除clearColor之外的任何颜色并将alpha属性设置为0.0;
Try setting the background color to whatever except the clearColor and setting the alpha property to 0.0;