【问题标题】:Button covered by another button, thus can't be tapped按钮被另一个按钮覆盖,因此无法点击
【发布时间】:2016-11-20 07:30:31
【问题描述】:

我在屏幕上有一个smallButton 和一个giantButton,在开始时giantButton 未启用,当smallButton 被点击时,它会隐藏并出现giantButton

我的问题是,似乎smallButtongiantButton 覆盖,当我点击smallButton 时,它的IBAction 不会被触发,它在故事板中链接得很好。

是因为smallButtongiantButton 覆盖,还是其他原因?

【问题讨论】:

  • 你把它们放在一起了吗?
  • @RashwanL 是的,我不能说哪一个正好在上面
  • 您可以在 viewLoads 时隐藏大按钮,在按下小按钮时取消隐藏,反之亦然
  • 问题解决了,谢谢大家!

标签: ios swift uiview


【解决方案1】:

如果您将 UIView 的任何实例设置为隐藏(或 alpha 0),它不会阻止 UI 交互。

看看禁用userInteractionEnabled 是否对您有帮助,或者您可以在您的子类中使用override func pointInside(point: CGPoint, withEvent event: UIEvent?) -> Bool 并通过...传递触摸事件...

【讨论】:

    【解决方案2】:

    我看到了问题,这个giantButton 包含在一个堆栈视图中,虽然我尝试隐藏/禁用giantButton,但这个堆栈视图仍然阻止我的交互。

    我根据@der_michael 的建议禁用了堆栈视图的用户交互,现在它可以工作了。

    【讨论】:

    • 您没有在问题中提到堆栈视图?
    • @der_michael ☺️ 甚至没有意识到它的存在
    猜你喜欢
    • 1970-01-01
    • 2015-04-04
    • 2021-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多