tags:

views:

17

answers:

1

I currently have a UI built in Interface Builder-- it is basically consisted of a background image and a few labels. I need to animate some elements (images) underneath the labels but over the background, but I also need to draw them in a specific z-order.

I was looking around and came across CATransformLayer-- I'm still looking into it. Is this the best way to manage the Z-order of images in order to simulate 3D? I don't want to use Open GL as the animation I am doing will be very simple fake 3D...

+1  A: 

Background:

On iPhone, UIViews have a subview NSArray. The root, a UIWindow is drawn first, then its subviews in order, then their subviews. In addition, there is a second hierarchy: each UIView has a CALayer array. The root CALayer draws first, then the each CALayer in order.

Suggestion:

Yes, you can do it as you outlined. However, the code may be a bit simpler if you do the following:

In your specific case, use a UIView to hold the background. Give it two subviews, initially transparent, full-size, with springs and struts set in Interface Builder to keep it the full size of the background. Arrange them in Interface Builder's outline view (-0) so that the UIView ImageViewHolder is listed before the UIView ButtonViewHolder.

That way, you can insert and remove UIImageViews from the ImageViewHolder UIView, and they'll be drawn above the background, and below the UIButtons.

DavidPhillipOster
Thanks! So if I add 3 different UIImageViews into a ImageViewHolder view, does the view that I add last or first draw on top? Also, if the first view I added draws on the bottom, is there a way to keep it on top?
Andrew M
-[addSubview: ] puts it at the end, so it draws last, but UIView has additional methods to let you put it where you want it in the draw order. Don't use ordinary NSMutableArray methods to change the subviews array, though.
DavidPhillipOster
Thanks for your help. It looks like I can use things like bringSubviewToFront to do what I want :)
Andrew M
Also insertSubview:atIndex: ; exchangeSubviewAtIndex:withSubviewAtIndex: ; insertSubview:belowSibView: ; insertSubview:aboveSubview: ;
DavidPhillipOster