Swift brings SubViewToFront not working

I have several shortcuts and buttons on the screen. To act on user clicks anywhere on the screen, I created a UIButton ("wholeScreenButton"), made my background clear and made it the same size as the supervisor. Now at runtime, I use the code below to add a button on top of every other label.

self.wholeScreenButton.bringSubviewToFront(self.wholeScreenButton) 

But it does not work. The user can still use some of the buttons, which should be under a full-screen window and should be inaccessible. What am I doing wrong?

+5
source share
2 answers

It should be like this:

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

You need to call showSubviewToFront on the parent view.

+14
source

try the following:

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

it will work every time for me

+2
source

Source: https://habr.com/ru/post/1206579/


All Articles