How to draw on a non-transformed context while zoomed in a CATiledLayer?

自作多情 提交于 2019-12-08 09:00:01

问题


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:


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



来源:https://stackoverflow.com/questions/3970988/how-to-draw-on-a-non-transformed-context-while-zoomed-in-a-catiledlayer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!