我正在使用 CATiledLayer 来可视化数据。默认情况下,drawLayer 函数获取一个转置和缩放的上下文,这允许绘图代码与缩放级别和请求的图块无关。
但是,我想使用缩放功能来改变数据的水平范围,而不发生实际的缩放。
到目前为止,我得到了这个代码:
(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 像素)有
什么方法可以防止这种模糊的发生吗?
或者,有什么方法可以吸引到未转换的上下文,而不是转置的上下文?