PDA

View Full Version : what does IB do when you tell a view it wants a layer




Chirone
Sep 7, 2010, 08:35 PM
I've noticed the option in IB to tick that it wants core animation layer
i tick it, and i can add sublayers to it in the awakeFromNib method

but if i try add the sublayers in the initWithFrame or initWithCoder methods the view doesn't have a layer at that time.

if i say self.layer = [[CALayer alloc] init] then i can add sublayers but the layer isn't setup the same way as it is when it comes from IB.
for instance, whatever is in drawRect in the view doesn't get drawn. I don't actually want to use the drawRect method, but that's irrelevant. IB has made a layer differently to how I did and i want to know what it did differently...



MorphingDragon
Sep 7, 2010, 10:04 PM
I've noticed the option in IB to tick that it wants core animation layer
i tick it, and i can add sublayers to it in the awakeFromNib method

but if i try add the sublayers in the initWithFrame or initWithCoder methods the view doesn't have a layer at that time.

if i say self.layer = [[CALayer alloc] init] then i can add sublayers but the layer isn't setup the same way as it is when it comes from IB.
for instance, whatever is in drawRect in the view doesn't get drawn. I don't actually want to use the drawRect method, but that's irrelevant. IB has made a layer differently to how I did and i want to know what it did differently...

awakeFromNib is called when everything in a particular NIBXIB file has been loaded and initialised. You can't see anything because might be trying to draw into a view which doesn't exist yet.

Try changing the order of the initialisations.

Chirone
Sep 7, 2010, 10:26 PM
the layers show up fine.
things just dont draw as they would if i did the setup after the view loads...

what happens if i want to create a view without a nib? the views layer wouldn't be set up the same (printing out the layers gives a different description depending on how you make it), i just want to know what else a nib does to the view's layer that just an [[CALayer alloc] init] doesn't do

kainjow
Sep 8, 2010, 03:30 AM
See -[NSView setWantsLayer:] - that turns on/off layers for a view.

Chirone
Sep 8, 2010, 07:43 AM
yeah i already know about that

what i'm saying is...
if you make a view in IB and tick the box to give it the core animation layer and in the awakeFromNib method you NSLog self.layer you get a big massive description

if you dont use IB and you go self.layer = [[CALayer alloc] init] you just get the memory address and <CALayer> printed out.

what I want to know is what the difference is between the two layers and why they have different descriptions

kainjow
Sep 8, 2010, 10:36 PM
The only difference is NSView has its own private layer it uses and the reason you see more when you log it is because it has implemented its own custom description method. I wouldn't worry anymore about it since it's an undocumented class.