views:

442

answers:

1

Hi,

Anyone know how to programmatically set the z order of UIImageViews? The order of instancing them will bring the last one instanced closest to the screen front, but how can it be changed at runtime?

Thanks // :)

+5  A: 

You can use the following if the UIImageView is already a subview:

  • bringSubviewToFront
  • sendSubviewToBack

or any of the following if you're inserting the UIImageView as a subview:

  • insertSubview:atIndex
  • insertSubview:aboveSubview
  • insertSubview:belowSubview
CiNN
Note that these methods are all defined on UIView, so you can use them on any kind of view, not just UIImageViews.
Mark Bessey
What if you have been adding the views with initWithParent rather than using subviews? Does initWithParent create subviews owned by the parent and kept in an index?
Spanky
never heard of initWithParent but yes, you can access them with whatever.subviews
CiNN
There is also exchangeSubviewAtIndex:withSubviewAtIndex:If CiNN's answer is good enough, why don't you select it as the answer? It helps to know what questions are in need of an answer and which aren't.
mahboudz