2010-10-06 57 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創建的。