CALayer.bounds - why is it always nil ??

Discussion in 'iOS Programming' started by teek, Apr 2, 2010.

  1. teek macrumors member

    teek

    Joined:
    Feb 12, 2008
    Location:
    Norway
    #1
    I've set up a CALayer for a simple animation.

    Code:
    	CALayer *monsterLayer = [CALayer layer];
    	[monsterLayer setContents:(id)monsterImage.CGImage];
    	[monsterLayer setFrame:CGRectMake(0,0,48,48)];
    	[monsterLayer setBounds:CGRectMake(0,0,48,48)];
    	//[monsterLayer setPosition:CGPointMake(100,100)];
    	[monsterLayer setBorderWidth:1.0f];
    	[monsterLayer setBorderColor:[UIColor orangeColor].CGColor];
    	[monsterLayer addAnimation:animation forKey:@"position"];
    
    	[self.layer insertSublayer:monsterLayer atIndex:0];
    
    	// touch posiotion to trigger animation
    	monsterLayer.position = CGPointZero;
       
            NSLog(@"monsterLayer: %@, monsterLayer.bounds);
    	NSLog(@"superlayer: %@", monsterLayer.superlayer.bounds);
    
    Both the bounds, frame, contentsRect and all the other possible CGRect properties return nil.

    Am I, or rather, what am I doing wrong here ?
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    CGRects are structs not objects so you can't use the %@ formatter.
     
  3. teek thread starter macrumors member

    teek

    Joined:
    Feb 12, 2008
    Location:
    Norway
    #3
    Ok I feel stupid, again.
    That resolved. I am struggeling with getting the current position of the monsterLayer.
    The monsterLayer is being animated using a pre-defined CGPath.
    Calling contentRect, bounds, frame, or any of the other methods on the layer does not return the x and y of the layer, only the height and width.
    Suggestions?
     
  4. teek thread starter macrumors member

    teek

    Joined:
    Feb 12, 2008
    Location:
    Norway
    #4
    I figured it out.

    Code:
    [[monsterLayer presentationLayer] frame] gives me what I want.
    
     

Share This Page