放大CATiledLayer时如何在未转换的上下文上绘制? [英] How to draw on a non-transformed context while zoomed in a CATiledLayer?
问题描述
我正在使用CATiledLayer来可视化数据。默认情况下,drawLayer函数获取转置和缩放的上下文,这使绘图代码与缩放级别和所请求的图块无关。
但是,我想使用缩放功能来更改数据的水平范围,而不会发生实际的缩放。
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 ..>
}
此方法有效,但缺点是放大时元素变得模糊。 (每个屏幕像素仅渲染1 / zoomfactor像素)。
是否有任何方法可以防止这种模糊现象发生?
或者,有什么方法可以吸引非转换的上下文,而不是转换的上下文?
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?
推荐答案
我认为我对这个问题的回答应该可以满足您的需求。
I think my answer to this question should do what you need.
这篇关于放大CATiledLayer时如何在未转换的上下文上绘制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!