隐藏 UILabel 下的 UIButton 不起作用
我有一个很大的 UILabel
,当我做其他事情时,我用它来覆盖一堆按钮。
我最初设置的是 myLabel.hidden = YES;
所以你看不到 UILabel
但 UIButtons
(在它下面)不会'不再工作了。
我可以使用 UILabel 的其他设置来允许触摸在隐藏时“穿过它”吗?谢谢。
I have a large UILabel
which I am using to cover a bunch of buttons while I do something else.
All I have set initially is myLabel.hidden = YES;
so you can't see the UILabel
but the UIButtons
(below it) won't work anymore.
Is there another setting for the UILabel
I can use to allow touches to go "through it" when it is hidden? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
为什么要使用 UILabel 来覆盖按钮。
只需设置
或
why use a UILabel to cover your buttons.
just set
or
您可以使用
addSubView
和removeFromSuperview
方法:当您想用 UILabel 隐藏 UIButton 时:
反之亦然:
You can use
addSubView
andremoveFromSuperview
methods :When you want to hide your UIButton with your UILabel :
and the contrary :
我不知道为什么隐藏会停止按钮上的触摸事件。无论如何,您可以通过以下调用显式地将按钮置于前台。
I am not sure why a hide is stopping the touch events on buttons. Anyways you can explicitly bring the buttons to foreground by the following calls.
作为隐藏或覆盖事物的通用方法的最简单的方法就是直接 UIView。 set:
它将拦截触摸并阻止对其下方按钮的触摸。
当您隐藏它或将 alpha 设置为 0.0 时,它应该停止阻止触摸;
您始终可以将覆盖视图交互切换到:
并且触摸将穿过它。
如果出于某种原因您需要 UILabel,这些方法也适用。
The simplest thing to use as a general way to hide or cover things just a straight UIView. set:
and it will intercept touches and block touches to the buttons below it.
It should stop blocking touches when you hide it or turn the alpha to 0.0;
You can always siwtch the covering views interaction to:
and touches will pass through it.
If there is some reason that you need the UILabel these methods will work with it also.
[myLabel setUserInteractionEnabled:否]。
即使被隐藏,您的标签仍然会受到影响。你必须禁用它才能实现你想要的。
[myLabel setUserInteractionEnabled:NO].
Even if is hidden, your label will get the touches anyway. You have to disable that to achieve what u want.
我认为你应该隐藏按钮而不是用标签覆盖它们。
I think you should hide your buttons instead of covering them with a label.