Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift bringSubViewToFront not working

I have a number of labels and buttons on the screen. To act on user tapping anywhere on the screen, I have created a UIButton ("wholeScreenButton"), made its background clear and made it the same size as superview. Now at runtime I am using below code to bring the button on top of every other label.

self.wholeScreenButton.bringSubviewToFront(self.wholeScreenButton)

But it is not working. User can still tap on some of the buttons which are supposed to be underneath the wholeScreenButton and supposed to be unreachable. What am I doing wrong?

like image 214
TPCO Avatar asked Nov 10 '14 18:11

TPCO


2 Answers

It should be this:

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

You need to call bringSubviewToFront on the parent view.

like image 80
Ron Fessler Avatar answered Sep 24 '22 09:09

Ron Fessler


try this:

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

this ll work everytime for me

like image 29
Pooja Patel Avatar answered Sep 24 '22 09:09

Pooja Patel