在iPhone 4上绘制CATiledLayer时,模糊像素跨越

在iPhone 4上绘制CATiledLayer时,模糊像素跨越,iphone,line,pixel,catiledlayer,blurry,Iphone,Line,Pixel,Catiledlayer,Blurry,我正在使用以下代码在CATiledLayer中绘制一条线: - (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx { CGContextMoveToPoint(ctx, 130, 100.5); CGContextAddLineToPoint(ctx, 160, 100.5); CGContextSetRGBStrokeColor(ctx, 1, 0, 0, 1); CGContextSetR

我正在使用以下代码在CATiledLayer中绘制一条线:

- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx {
    CGContextMoveToPoint(ctx, 130, 100.5);
    CGContextAddLineToPoint(ctx, 160, 100.5);
    CGContextSetRGBStrokeColor(ctx, 1, 0, 0, 1);
    CGContextSetRGBFillColor(ctx, 1, 0, 0, 1);
    CGContextDrawPath(ctx, kCGPathStroke);
}
我得到的是这条4倍模糊的线:

如果我将CATiledLayer更改为CALayer,则线条会很锐利,其宽度为2px,如预期的那样。 我只在iPhone4上看到这种行为,在3GS上,CALayer和CATiledLayer的线条都很清晰。当然,在3GS上,线的厚度是1px

你知道如何克服这种行为吗

我找到了: CATiledLayer是使用ContentsCale==1.0创建的。如果将其附加到contentScaleFactor==2.0的视图,则该层将被放大,这就是我的图形中出现问题的地方

解决方案: 将layer.ContentsCale设置为2.0,然后再将其附着到视图

苹果公司说,任何创建的未附加到视图的层,其contentScale==1.0,但在我的测试中,CALayer是使用contentScale==2创建的