隐藏 UILabel 下的 UIButton 不起作用

发布于 2024-11-18 16:34:32 字数 219 浏览 6 评论 0原文

我有一个很大的 UILabel,当我做其他事情时,我用它来覆盖一堆按钮。
我最初设置的是 myLabel.hidden = YES; 所以你看不到 UILabelUIButtons (在它下面)不会'不再工作了。

我可以使用 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 技术交流群。

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

发布评论

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

评论(6

青衫负雪 2024-11-25 16:34:32

为什么要使用 UILabel 来覆盖按钮。

只需设置

UIButton *button;
[button setUserInteractionEnabled:NO];

[button setUserInteractionEnabled:YES];

why use a UILabel to cover your buttons.

just set

UIButton *button;
[button setUserInteractionEnabled:NO];

or

[button setUserInteractionEnabled:YES];
我也只是我 2024-11-25 16:34:32

您可以使用 addSubViewremoveFromSuperview 方法:

当您想用 UILabel 隐藏 UIButton 时:

[self.view addSubview:myLabel];

反之亦然:

[myLabel removeFromSuperview];

You can use addSubView and removeFromSuperview methods :

When you want to hide your UIButton with your UILabel :

[self.view addSubview:myLabel];

and the contrary :

[myLabel removeFromSuperview];
离笑几人歌 2024-11-25 16:34:32

我不知道为什么隐藏会停止按钮上的触摸事件。无论如何,您可以通过以下调用显式地将按钮置于前台。

[self bringSubviewToFront:button];

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.

[self bringSubviewToFront:button];
木落 2024-11-25 16:34:32

作为隐藏或覆盖事物的通用方法的最简单的方法就是直接 UIView。 set:

[myCoverView setUserInteractionEnabled:YES]; 

它将拦截触摸并阻止对其下方按钮的触摸。

当您隐藏它或将 alpha 设置为 0.0 时,它应该停止阻止触摸;
您始终可以将覆盖视图交互切换到:

[myCoverView setUserInteractionEnabled:NO]; 

并且触摸将穿过它。

如果出于某种原因您需要 UILabel,这些方法也适用。

The simplest thing to use as a general way to hide or cover things just a straight UIView. set:

[myCoverView setUserInteractionEnabled:YES]; 

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:

[myCoverView setUserInteractionEnabled:NO]; 

and touches will pass through it.

If there is some reason that you need the UILabel these methods will work with it also.

你列表最软的妹 2024-11-25 16:34:32

[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.

梦魇绽荼蘼 2024-11-25 16:34:32

我认为你应该隐藏按钮而不是用标签覆盖它们。

[yourButton setHidden = YES]; 
[yourButton2 setHidden = YES]; 
...

I think you should hide your buttons instead of covering them with a label.

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