【问题标题】:Swift bringSubViewToFront not working斯威夫特带来SubViewToFront 不工作
【发布时间】:2015-01-07 03:39:23
【问题描述】:

我在屏幕上有许多标签和按钮。为了让用户点击屏幕上的任意位置,我创建了一个 UIButton(“wholeScreenButton”),使其背景清晰,并使其与 superview 大小相同。现在在运行时,我使用下面的代码将按钮置于其他标签之上。

self.wholeScreenButton.bringSubviewToFront(self.wholeScreenButton)

但它不起作用。用户仍然可以点击一些应该位于 wholeScreenButton 下方并且应该无法访问的按钮。 我做错了什么?

【问题讨论】:

    标签: ios swift xcode cocoa-touch uiview


    【解决方案1】:

    应该是这样的:

    self.view.bringSubview(toFront: self.wholeScreenButton)
    

    您需要在父视图上调用bringSubviewToFront。

    【讨论】:

    • 如何对 UIBarButton 执行此操作? @ronfessler
    【解决方案2】:

    试试这个:

    self.wholeScreenButton.superView.bringSubviewToFront(self.wholeScreenButton)
    

    这对我每次都有效

    【讨论】:

    • 这是绕圈子。更简单的方法是 self.view.bringSubviewToFront()
    【解决方案3】:

    Swift 5.1

    view.bringSubviewToFront(self.wholeScreenButton)

    【讨论】:

      猜你喜欢
      • 2016-02-16
      • 2016-12-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-24
      • 2017-07-22
      相关资源
      最近更新 更多