views:

612

answers:

5

How do I arrange (in terms of depth) a view's subview to be in front of another view?

The hierarchy looks like this:

A--
   -C
   -D
B--
   -E
   -F

(A and B are views with C & D, and E & F, as subviews, respectively.)

B is layered above A, so every subview in B (E and F) is above every subview in A (C and D). How can I make C display above everything in B, but have the rest remain as it should be?

In other words, how can I make the order of displayed views (the first in the list is the topmost, with the next one drawn behind it):

C
B
E & F (same level)
A
D

Thanks, Arseniy

+1  A: 

Have you tried using UIView methods to move/relocate views?

insertSubview:aboveSubview:
insertSubview:atIndex:
insertSubview:belowSubview:
addSubViews:
bringSubviewToFront:
removeFromSuperview:
Jordan
Those only work in relation to the view of which it is a subview. Those don't alter the order of views in relation to other unrelated superviews.
Arseniy Banayev
A: 

IF you want C to display above everything in B, make it a subview of B.

NSResponder
+2  A: 

You cannot do it the way you describe it. Either view A or B is frontmost, if you want to show view C in front of view B, but want to keep A and D behind it, you need to take C out of view A and show it at the same level as A & B.

Johan Kool
Unfortunately, this seems to be the case. Taking C out of view A is the only way to do it, and that's what I ended up doing.
Arseniy Banayev
A: 

Why not make C a parent view of both A and B. This should do what you want.

C
  -B
    -E
    -F
  -A
    -D

Use the functions in Managing the view hierarchy to rearrange your view hierarchy.

sfa
A: 

Is A and B UIViewControllers? And C,D,E,F UIViews added to these controllers? You're not being very clear.

If they are all subViews of a UIViewController then see my earlier post.

Jordan