Search code examples
iphoneobjective-ccalayerquartz-graphics

How to get absolute position of point inside CALayer


how can I obtain the absolute position of a CGPoint inside a CALayer. I need this for exact pixel drawing

Edit: Absolute to the screen


Solution

  • Hit test the superlayers recursively, until you arrive at the root layer:

    CGPoint originalPoint = // wherever from you obtain your original point
    CALayer *layer = self;
    CGPoint point = originalPoint;
    while (layer.superlayer)
    {
        point = [layer convertPoint:point toLayer:layer.superlayer];
        layer = layer.superlayer;
    }
    
    // here `point' will contain the exact position