Imagen de recorte de CAShapeLayer

I am trying to crop an image using CAShapeLayer with this code

    CALayer* contentLayer = [CALayer layer];
    CAShapeLayer* mask = [CAShapeLayer layer];

    CGMutablePathRef path = CGPathCreateMutable();

    CGPathMoveToPoint(path, NULL, 10, 10);
    CGPathAddLineToPoint(path, NULL, 10, 80);
    CGPathAddLineToPoint(path, NULL, 80, 80);
    CGPathAddLineToPoint(path, NULL, 80, 10);
    mask.path = path;

    [contentLayer setContents:(id)[[UIImage imageNamed:@"image.png"] CGImage]];
    [contentLayer setMask:mask];          

    [[self layer]addSublayer:contentLayer];

After executing this I can see just empty view;

preguntado el 09 de marzo de 12 a las 16:03

1 Respuestas

You never set the frame de tu contentLayer, so it defaults to CGRectZero, which makes its contents invisible. Set the frame to have the size of your image and you should see it.

respondido 09 mar '12, 16:03

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.