Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
746 views
Welcome To Ask or Share your Answers For Others

1 Answer

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];

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...