Tagging CALayers in iPhone

Peyman picture Peyman · May 18, 2010 · Viewed 11.6k times · Source

I am looking for a general way to be able to search for a unique CALayer in a hierarchy without having to remember where the layer is in a hierarchy (and use the sublayer: and superlayer: methods).

I know this is possible with UIViews (which makes flipping views easy) but is it possible for CALayer?

thank you in advance for your help

Peyman

Answer

Mshah2 picture Mshah2 · Nov 11, 2010

You can also use the name property of the CALayer.

[layer setName:@"myKey"];

To look it up,

- (CALayer *)myLayer {

    for (CALayer *layer in [superLayerOfMyLayer sublayers]) {

            if ([[layer name] isEqualToString:LabelLayerName]) {
                return layer;
            }
    }

    return nil;
}