2010-10-06 63 views
2

我用下面的代码绘制在CATiledLayer线在CATiledLayer绘制时跨越:模糊像素的iPhone 4

- (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); 
} 

我得到的是这个4PX模糊的行:

http://img837.imageshack.us/img837/5002/fuzzyline.png

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

任何想法如何克服这种行为。

回答

1

我找到了它: CATAILLAYER获取与contentsScale == 1.0创建。如果使用contentScaleFactor == 2.0将它附加到视图上,图层会变大,这里是我的绘图螺旋的位置。

解决方案: 在附加视图之前设置layer.contentsScale = 2.0。

Apple表示任何创建的视图没有附加到contentScale == 1.0,但在我的测试中,CALayer是使用contentScale == 2创建的。