I'm building up a grid of images, and I start at the top, creating UIImageView objects all over the place. Now I want that they overlap a little bit, but the last ones I draw are the ones most on top. I'd like to set the z-position programmatically, so that the first ones I draw will be the ones most on top.
views:
1326answers:
3Not directly.
One solution would be giving the UIViews a z-index property; an integer defining your depth level. Then you could itterate through an NSArray (myArray) containing the UIViews adding them as subviews in order of depth.
Actually, as far as I know, there is no z-index position property for that. Drawing in the view uses a simple drawing model.
You can either put your logic in the drawing loop (i.e draw the things you want on top last) or you can use Cocoa Animation, since unlike UIImageView, CALayers do have depth (they are a 2D projection of a 3D space). See here for a reference.
You said you used UIImageView. Drawing an image with UIImageView means initializing it and then adding it to a container view.
Can't you just use this code in your loop?
[containerView insertSubview:image atIndex:[[containerView subviews] count]]
The result would be that the view added first is on the top of the view stack (I haven't been able to test this yet though :) )