Swift带来了SubViewToFront无法正常工作

TPC*_*PCO 8 ios swift

我在屏幕上有许多标签和按钮.为了对用户点击屏幕上的任何位置进行操作,我创建了一个UIButton("wholeScreenButton"),使其背景清晰并使其与superview的大小相同.现在在运行时我使用下面的代码将按钮放在每个其他标签的顶部.

self.wholeScreenButton.bringSubviewToFront(self.wholeScreenButton)
Run Code Online (Sandbox Code Playgroud)

但它没有用.用户仍然可以点击一些应该在wholeScreenButton下面并且应该无法访问的按钮.我究竟做错了什么?

Ron*_*ler 21

它应该是这样的:

self.view.bringSubview(toFront: self.wholeScreenButton)
Run Code Online (Sandbox Code Playgroud)

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