我使用CoreGraphics在自定义SGCircleView中绘制圆。由于我希望在触摸圆形时使用径向渐变填充,因此我的应用是使用原始圆形(SGCircleLayer)绘制一个图层,然后添加另一个带有渐变的图层。问题是这些圆圈看起来像是“颗粒状”的。
这是SGCircleLayer中的代码:
- (void) drawLayer: (CALayer *) layer inContext: (CGContextRef) ctx {
UIGraphicsPushContext(ctx);
UIBezierPath *circlePath = [UIBezierPath bezierPathWithOvalInRect: CGRectInset(layer.bounds, CLineWidth / 2, CLineWidth / 2)];
self.path = circlePath.CGPath;
[[UIColor whiteColor] setStroke];
circlePath.lineWidth = CLineWidth;
[circlePath stroke];
UIGraphicsPopContext();
}出于测试目的,我添加了另一个圆,它的半径和线宽与自定义SGCircleTestView的drawRect中绘制的半径和线宽完全相同,看起来非常平滑。
这是我的drawRect在SGCircleTestView (平滑圆)中的代码:
- (void) drawRect: (CGRect) rect {
CGRect bounds = CGRectInset(rect, CLineWidth * 0.5, CLineWidth * 0.5);
UIBezierPath* circlePath = [UIBezierPath bezierPathWithOvalInRect: bounds];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, CLineWidth2);
CGContextSetStrokeColorWithColor(context, [UIColor whiteColor].CGColor);
[circlePath stroke];
}我在绘制SGCircleLayer的代码时做错了什么?

发布于 2014-12-04 16:13:56
您可能需要将层的contentsScale设置为与屏幕相同。
layer.contentsScale = [UIScreen mainScreen].scale;发布于 2014-08-14 16:57:17
不推荐使用CGLayer :)
http://iosptl.com/posts/cglayer-no-longer-recommended/
https://stackoverflow.com/questions/18570432
复制相似问题