UIBezierPath无法绘制出完美的圆圈

时间:2015-05-27 10:07:26

标签: ios uikit uibezierpath

我正在使用UIBezierPath绘制像

这样的圆圈
UIBezierPath *outerPath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(heigth/2.0f, heigth/2.0f)
                                                             radius:(self.frame.size.height * 0.5)
                                                         startAngle:DEGREES_TO_RADIANS(-90)
                                                           endAngle:DEGREES_TO_RADIANS(270)
                                                          clockwise:YES];
outerCircleLayer = [CAShapeLayer layer];

outerCircleLayer.lineCap = kCALineCapRound;
outerCircleLayer.lineWidth = 1.0f;
outerCircleLayer.strokeColor = HexRGB(0x4cae7b).CGColor;
outerCircleLayer.fillColor = [[UIColor clearColor] CGColor];
outerCircleLayer.path = outerPath.CGPath;
outerCircleLayer.strokeEnd = 0;

但我发现圆圈并不完美,就像下面的

enter image description here enter image description here

我该怎么办?

更新:

更新图片,从这里我们可以发现起点和终点不平滑。enter image description here

1 个答案:

答案 0 :(得分:0)

在使用CAShapeLayer创建平滑圆圈时,您需要设置shouldRasterize并同时提供rasterizationScale。这些基本上是CAShapeLayer

的属性
layer = [CAShapeLayer layer];

// customize layer

// set shouldRasterize & rasterizationScale
layer.shouldRasterize = YES;
layer.rasterizationScale = [UIScreen mainScreen].scale;