2011-05-20 143 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