How to set iPhone UIView z index?

Tattat picture Tattat · Jan 8, 2011 · Viewed 214.8k times · Source

I want to move one view on top of another, how can I know the z index of the view, and how to move on to top?

Answer

You can use the zPosition property of the view's layer (it's a CALayer object) to change the z-index of the view.

theView.layer.zPosition = 1;

As Viktor Nordling added, "big values are on top. You can use any values you want, including negative values." The default value is 0.

You need to import the QuartzCore framework to access the layer. Just add this line of code at the top of your implementation file.

#import "QuartzCore/QuartzCore.h"