1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

what does IB do when you tell a view it wants a layer

Discussion in 'Mac Programming' started by Chirone, Sep 7, 2010.

  1. macrumors 6502

    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...
  2. macrumors 603


    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.
  3. macrumors 6502

    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
  4. Moderator emeritus


    See -[NSView setWantsLayer:] - that turns on/off layers for a view.
  5. macrumors 6502

    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
  6. Moderator emeritus


    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.

Share This Page