Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tagging CALayers in iPhone

Tags:

search

calayer

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

like image 474
Peyman Avatar asked May 17 '10 23:05

Peyman


2 Answers

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; } 
like image 80
Mshah2 Avatar answered Oct 08 '22 02:10

Mshah2


Apologize. I was being a dunce. CALayer is a key-value coding compliant container so I can create arbitrary values (including tags) in any instance. To create a tag for instance we do:

[rootLayer setValue:[NSNumber numberWithInt:101] forKey:@"PFtag"]; 

thank you

like image 20
Peyman Avatar answered Oct 08 '22 02:10

Peyman