core animation, layers do not show up at all unless constrained...

Discussion in 'Mac Programming' started by Chirone, May 17, 2009.

  1. Chirone macrumors 6502

    Joined:
    Mar 2, 2009
    Location:
    NZ
    #1
    i'm trying to get a text layer and just a normal CA layer (so i can use core graphics on it) to start in a particular position

    right now the textlayer does not show up unless it has a constraint applied to it

    which is pointless since constraining the width doesn't scale the layer (just the box), which is what i need...
    the whole
    Code:
    [wordOne setValue: [NSNumber numberWithFloat: 200] forKeyPath: @"transform.translation.x"];
    line doesn't have any effect, and calling setNeedsDisplay doesn't do anything either :confused: (regardless of whether or not the layer is constrained)

    if that's not the correct way to change the position of something then i'm totally lost... i suppose i could use the constraint's offset for translation, but that doesn't help for trying to rotate and scale the layers...
     
  2. WhiteRabbit macrumors newbie

    Joined:
    Jan 11, 2005
    #2
    The frame (position and bounds) must be set inorder for a layer to be visible. A textLayer uses bounds for wrapping, if you want to "scale" the layer you'll have to change the font size.
     
  3. Chirone thread starter macrumors 6502

    Joined:
    Mar 2, 2009
    Location:
    NZ
    #3
    so unless the frame and bounds are constrained the layer has 0 frame and bounds?
    that just sounds silly :rolleyes:
    oh well... i guess it's all guess and check for deciding the tightest frame and bounds... seems pretty silly to me. knowing the width of a word seems to be the most useful thing for my app but it's just not something that can be obtained easily

    look's like i will have to use a normal CALayer with core graphics on it to get proper scaling of text too... seeing as how scaling a text layer doesn't actually scale the contents :(

    thanks for the clarification whiterabbit :)
     
  4. WhiteRabbit macrumors newbie

    Joined:
    Jan 11, 2005
    #4
    If you set the layer frame via setFrame or setBounds and setPosition you shouldn't need to use a constraint.

    If you center the text virtically and horizontally in the layer (and the layer is bigger than the text) you could use the fontSize property in an animation or whatever to scale the text.
     
  5. Chirone thread starter macrumors 6502

    Joined:
    Mar 2, 2009
    Location:
    NZ
    #5
    i know that, i'm just saying it's silly that you have to manually set it yourself for a CATextLayer, it should automatically resize as the text changes
     

Share This Page