I'm wondering if there is a way to bring layer on top of others layers of view. Something like bringSubviewToFront
does for UIView
class. I think it can be done with zPosition
property of the CALayer
but this means I have to check zPosition
for all layers and then set proper value.
Thanks in advance.
I believe that the code (given that layer
is your CALayer
)
[layer retain];
CALayer *superlayer = layer.superlayer;
[layer removeFromSuperlayer];
[superlayer addLayer:layer];
[layer release];
will do what you want, albeit in a roundabout way.
It's even easier. If sublayerToBeMovedToFront
is the layer you're moving and itsSuperLayer
is, well, its superlayer, just say:
[itsSuperLayer addSublayer:sublayerToBeMovedToFront];
The addSublayer
call simultaneously unhookssublayerToBeMovedToFront
from wherever it was in the sibling list and rehooks it as the last (ie, frontmost-positioned, visually "on top") sublayer. This is exactly analogous behaviour to that of [aUIView addSubview:]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With