2011-05-20 124 views
5

問候!我試圖在駐留在可縮放UISCrollView中的CALayer中繪製一系列圓圈。這是可以縮放的圖層。如果我畫使用CAShapeLayer圓圈,然後他們放大精美:CALayer的抗鋸齒圖紙

CAShapeLayer plotLayer = [CAShapeLayer layer]; 
plotLayer.bounds = self.bounds; 
plotLayer.anchorPoint = CGPointZero; 
plotLayer.position = CGPointZero; 

CGMutablePathRef path = CGPathCreateMutable(); 
for (id one in many) { 
    CGRect ellipseRect = [one circleRect]; 
    CGPathAddEllipseInRect(path, NULL, ellipseRect); 
} 
plotLayer.path = path 
CFRelease(path); 
[self.layer addSublayer:plotLayer]; 
[plotLayer setNeedsDisplay]; 

然而,當我嘗試用香草核心圖形畫在我的drawLayer:inContext的:法,圓得非常鋸齒(徹頭徹尾的親走樣!)抗鋸齒暗中搗鬼再多似乎幫助:

-(void)drawLayer:(CALayer *)layer inContext:(CGContextRef)context 
{ 
    CGContextSetAllowsAntialiasing(context, true); 
    CGContextSetShouldAntialias(context, true); 
    CGContextClip(context); 

    for (id one in many) { 
     CGRect ellipseRect = [one circleRect]; 
     CGContextStrokeEllipseInRect(context, ellipseRect); 
    } 
} 

我試圖找出CAShapeLayer做能得到這樣好的抗鋸齒使(除了我自己的薰陶),我可以充分利用我的繪圖中的核心圖形,而不僅僅是我可以用CAShapeLayer獲得的筆畫/填充。我是否錯過了某處的轉換?

非常感謝!

回答

3

簡短的回答:contentsScale

較長的答案:(在Vector like drawing for zoomable UIScrollView從pe8ter幾乎逐字):

您可以通過設定問題的層上contentScale性能得到更好的渲染放大後:

- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView 
         withView:(UIView *)view 
         atScale:(float)scale 
{ 
    [CATransaction begin]; 
    [CATransaction setValue:[NSNumber numberWithBool:YES] 
        forKey:kCATransactionDisableActions]; 
    uglyBlurryTextLayer.contentsScale = scale; 
    [CATransaction commit]; 
} 

有由當實際抽籤發生的布拉德拉爾森(擾流板(通常優)的描述中,usua只有在應用了多少次轉換後纔會發生一次),其位置爲So a CALayer does not contain a content bitmap of a view?。基於此,我只能假設設置contentsScale導致圖層再次呈現。

0

我還沒有嘗試過,但如果您的圓圈在調整視圖大小時變得鋸齒,這可能是因爲插值質量。

您是否嘗試將插值質量設置爲高?

CGContextSetInterpolationQuality(context, kCGInterpolationHigh); 
+1

感謝您的想法,但沒有運氣。 CGContextSetInterpolationQuality不起作用。我也試過CGContextSetFlatness,它也沒有效果。 – kalperin 2011-05-27 16:20:03