views:

918

answers:

3

I'm doing a bit of UIView wrangling and am stuck. It is straightforward changing the "z" order of sibling subviews. [mySuperview sendSubviewToBack:mySubview] places mySubview behind all it's siblings.

But how do I place a subview behind it's parent?

Thanks, Doug

+2  A: 

You can't as far as I know. You'll have to remove it from the parent then add it to the parent's parent's subviews.

UIView *parent = view.superview;
[view removeFromSuperview];

/* Adjust frame to realign under parent view */

[parent.superview addSubview:view];
Nick Bedford
A: 

you can use the [self.view addSuview:(UIView *) belowSubview:(UIView *)] method to do this pretty easily

Sj
+1  A: 

You may want to put both into a container view, so that you can properly place one behind the other without affecting a superview not really meant to hold arbitrary views (although that will probably work just fine).

Kendall Helmstetter Gelner
Thanks Kendall. Yes, that looks like my only option. It's too bad altering the 'z' relationship between parent and child is not available. Probably has something to do with the iPhone compositing engine. Cheers.
dugla
One other thing I ran across, you could try altering the "anchorPointZ" property of the view.layer... I'm not sure which way you would set it.
Kendall Helmstetter Gelner