首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何提高CGLayer的绘图质量

如何提高CGLayer的绘图质量
EN

Stack Overflow用户
提问于 2013-09-02 17:59:33
回答 2查看 769关注 0票数 1

我使用CoreGraphics在自定义SGCircleView中绘制圆。由于我希望在触摸圆形时使用径向渐变填充,因此我的应用是使用原始圆形(SGCircleLayer)绘制一个图层,然后添加另一个带有渐变的图层。问题是这些圆圈看起来像是“颗粒状”的。

这是SGCircleLayer中的代码:

代码语言:javascript
复制
- (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 (平滑圆)中的代码:

代码语言:javascript
复制
- (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的代码时做错了什么?

EN

回答 2

Stack Overflow用户

发布于 2014-12-04 16:13:56

您可能需要将层的contentsScale设置为与屏幕相同。

代码语言:javascript
复制
layer.contentsScale = [UIScreen mainScreen].scale;
票数 1
EN

Stack Overflow用户

发布于 2014-08-14 16:57:17

不推荐使用CGLayer :)

http://iosptl.com/posts/cglayer-no-longer-recommended/

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18570432

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档