iOS Core Animation: CALayer bringSublayerToFront?

ma11hew28 picture ma11hew28 · Jul 1, 2011 · Viewed 29.6k times · Source

How do I bring a CALayer sublayer to the front of all sublayers, analogous to -[UIView bringSubviewToFront]?

Answer

Shaun Budhram picture Shaun Budhram · May 22, 2014

I'm curious why none of these answers mention the zPosition attribute on CALayer. Core Animation looks at this attribute to figure out layer rendering order. The higher the value, the closer it is to the front. These answers all work as long as your zPosition is 0, but to easily bring a layer to the front, set its zPosition value higher than all other sublayers.