How to bring a subview to the front when you click it?

I have a view with approximately 30 subviews on it. I want to add code to my subview view manager, so when I click subview, the subview expands to fill the screen.

I use [self.view setFrame:rect] to extend the subview, and it works fine. The problem is that some of the other 29 subzones above the supervision I just clicked on, so they are still visible.

I tried using bringSubviewToFront from the parent view controller, but this does not seem to have any effect. Is there any code that I can add to the subview viewcontroller class to make this happen?

+57
ios
Mar 17 2018-11-21T00:
source share
4 answers

bringSubviewToFront should work, just make sure you use it correctly. Using.

 [parentView bringSubviewToFront:childView]; 
+155
Mar 17 '11 at 21:32
source share

Use this code even if you do not know about superView:

In objective-c:

 [subview.superview bringSubviewToFront: subview]; 

Quickly:

 subview.superview?.bringSubview(toFront: subview) 
+11
Aug 08 '16 at 13:11
source share

In objective-c:

 [self.superview bringSubviewToFront: subview]; 

In swift2.3:

 self.superview!.bringSubviewToFront(subview) 

In swift3.1.1:

 superview.bringSubview(toFront: subview) 
+2
Aug 10 '17 at 12:46 on
source share

For ease of use, the extension in Swift 3

 extension UIView { func bringToFront() { self.superview?.bringSubview(toFront: self) } } 
+1
Aug 10 '17 at 12:22
source share



All Articles