我在屏幕上有许多标签和按钮。为了响应用户点击屏幕上的任何位置,我创建了一个UIButton ("wholeScreenButton"),使其背景清晰,并使其与superview大小相同。现在,在运行时,我使用下面的代码将按钮放在每个其他标签的顶部。
self.wholeScreenButton.bringSubviewToFront(self.wholeScreenButton)但它不起作用。用户仍然可以点击一些按键,这些按键应该在wholeScreenButton下面,并且应该是无法触及的。我做错了什么?
发布于 2014-11-11 05:33:03
应该是这样的:
self.view.bringSubview(toFront: self.wholeScreenButton)您需要在父视图上调用bringSubviewToFront。
发布于 2015-09-07 16:47:48
试试这个:
self.wholeScreenButton.superView.bringSubviewToFront(self.wholeScreenButton)这对我来说每次都会起作用。
发布于 2021-01-27 20:38:36
在Swift 5.1中
view.bringSubviewToFront(self.wholeScreenButton)
https://stackoverflow.com/questions/26850501
复制相似问题