Core animation image not drawn

Discussion in 'Mac Programming' started by ramy1989, Dec 2, 2012.

  1. macrumors newbie

    Joined:
    Nov 7, 2012
    #1
    I have opened a similar question on SO but no one answered yet.
    I have a CALayer and I'm trying to draw an image inside it:

    Code:
    NSBundle* mainBundle= [NSBundle mainBundle];
    NSString* imagePath= [mainBundle pathForImageResource: @"shark.jpeg"];
    NSImage* sharkImage= [[NSImage alloc]initWithContentsOfFile: imagePath];
    CALayer* layer=[[CALayer alloc]init];
    layer.anchorPoint= CGPointZero;
    layer.position= CGPointMake(200, 150);
    layer.backgroundColor= CGColorGetConstantColor(kCGColorWhite);
    layer.borderWidth=20;
    layer.borderColor= CGColorGetConstantColor(kCGColorBlack);
    layer.cornerRadius=15;
    layer.shadowOpacity=0.5;
    view.wantsLayer= YES;
    [sharkImage drawInRect: layer.bounds fromRect: NSZeroRect operation: NSCompositeCopy fraction: 1.0];
    [CATransaction begin];
    [view.layer addSublayer: layer];
    [CATransaction commit];
    
    The image is loaded succesfully and I know this through debugging.
    But nothing is shown in the layer, why?
     

Share This Page