代码之家  ›  专栏  ›  技术社区  ›  TinkerTank

如何在缩放CATiledLayer时在未转换的上下文上绘制?

  •  1
  • TinkerTank  · 技术社区  · 14 年前


    但是,我想使用缩放功能来更改数据的水平范围,而不需要实际缩放。

    到目前为止,我得到了这个密码:

    (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像素)
    有什么方法可以防止这种模糊发生吗?
    或者,是否有任何方法可以绘制到非转换的上下文,而不是转置的上下文?

    1 回复  |  直到 12 年前
        1
  •  2
  •   Community CDub    8 年前

    我想 my answer to this question 应该做你需要的。

    推荐文章