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?
It should be this:
self.view.bringSubview(toFront: self.wholeScreenButton)
You need to call bringSubviewToFront on the parent view.
try this:
self.wholeScreenButton.superView.bringSubviewToFront(self.wholeScreenButton)
this ll work everytime for me
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With