views:

25

answers:

1

I'm using a CATiledLayer for the visualisation of data. By default the drawLayer function gets a transposed and scaled context, which allow the drawing code to be agnostic of the zoom-level and the tile that's being requested.
However, I would like to use the zoom functionality to change the horizontal range of the data, without actual zooming occuring.

So far, I got this code:

(void)drawLayer:(CALayer*)layer inContext:(CGContextRef)context {

    /* retrieve the transformation matrix from the context. */
    CGAffineTransform contextTrans = CGContextGetCTM(context); 

    /* Scale the context back, so all items will still have the same size */
    CGContextScaleCTM(context, 1.0/contextTrans.a, 1.0/contextTrans.d); 

    <.. loop through all datapoints ..> {
        /* Transpose the point-centers to the new zoomed context */
        xCoord = xCoord * contextTrans.a;
        yCoord = yCoord * contextTrans.d;
    }
    <.. drawing code ..>
}

This works, but has the disadvantage that the elements get blurry when zoomed in. (only 1/zoomfactor pixels are rendered for each on-screen pixel)
Any methods to prevent this blurryness from happening?
Alternatively, is there any way to draw to the non-transformed context, rather than the transposed one?

+1  A: 

I think my answer to this question should do what you need.

Jacques