简体   繁体   English

UIButton 被视图覆盖(或半覆盖)时禁用

[英]UIButton disabled when covered (or semi covered) by a view

I have a view that holds some UIButtons.我有一个包含一些 UIButtons 的视图。 Another view covers and hides the buttons.另一个视图覆盖并隐藏了按钮。 When the top view slides off to reveal the buttons (with an animation).. the UI draws the buttons grayed out until the top view no longer covers or overlaps the buttons at all.. causing an undesirable flicker from gray to the normal button color (white).当顶视图滑开以显示按钮(带有动画)时.. UI 将按钮绘制为灰色,直到顶视图不再覆盖或完全覆盖按钮.. 导致从灰色到正常按钮颜色的不希望的闪烁(白色的)。

is there a way to keep the UIButton from rendering itself disabled while covered or semi covered by another view?有没有办法让 UIButton 在被另一个视图覆盖或半覆盖时使其自身处于禁用状态?

I dont think that its correct that a button is disabled while covered.我认为在覆盖时禁用按钮是不正确的。 What is happening is that when its covered, touch events are prevented from getting to the button, so the button cant get pressed.发生的事情是,当它被覆盖时,触摸事件被阻止到达按钮,因此按钮无法被按下。 If the button is only partially covered, touch events to that part that are not covered can be received by the button and the button can be depressed.如果按钮仅被部分覆盖,则按钮可以接收到未覆盖部分的触摸事件,并且可以按下按钮。 If you really wanted the button to work while it was covered (maybe you can relayer your views so the button is in front of the view instead of behind it?) you could hack your view and void its hit testing so it doesnt capture the touches.如果您真的希望按钮在被覆盖时工作(也许您可以中继您的视图,以便按钮位于视图前面而不是后面?)您可以破解您的视图并使其命中测试无效,因此它不会捕获触摸.

Well, in lieu of actually finding the correct answer, I simply swapped out the buttons with UIImageViews and attached UITapGestureRecognizers to them... this solved the problem.好吧,代替实际找到正确答案,我只是用 UIImageViews 替换了按钮并将 UITapGestureRecognizers 附加到它们......这解决了问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM