Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bringSubviewToFront problem?

HI, I have Parentview-->Multiple childviews. when i use [self bringSubviewToFront:childview] in parentview, it works fine.but after adding grandchildview to childview,when i use [self bringSubviewToFront: grandchildview] in parentview, it did not work?any help please?

like image 748
senthilM Avatar asked Sep 22 '10 06:09

senthilM


2 Answers

The -[UIView bringSubviewToFront:] method only works for direct children, not grandchildren. Remember that the view hierarchy is a tree, and normally a view only knows about its "parent" (or superview) and its direct "children" (or subviews). You would need to do something like this:

// First, get the view embedding the grandchildview to front.
[self bringSubviewToFront:[grandchildview superview]];
// Now, inside that container view, get the "grandchildview" to front. 
[[grandchildview superview] bringSubviewToFront:grandchildview];
like image 130
DarkDust Avatar answered Oct 20 '22 17:10

DarkDust


my contribution with the swift version from the checked solution

self.bringSubviewToFront(self.grandchildview.superview!)
self.grandchildview.superview!.bringSubviewToFront(self.grandchildview)
like image 22
Kevin ABRIOUX Avatar answered Oct 20 '22 16:10

Kevin ABRIOUX