我在我的类中有这两个函数,它们扩展了 CAShapeLayer,但是每次我绘制路径时都无法得到带有圆形端盖的弧。它看起来总是这样的图片:
我已经尝试使用 kCALineCapRound 没有成功。有任何想法吗?
self.lineShape.lineCap = kCALineCapRound;
self.lineShape.lineJoin = kCALineJoinRound;
private func mask() {
let maskLayer = CAShapeLayer()
maskLayer.bounds = self.bounds
let ovalRect = self.hollowRect
let path = UIBezierPath(ovalInRect: ovalRect)
path.appendPath(UIBezierPath(rect: maskLayer.bounds))
maskLayer.path = path.CGPath
maskLayer.lineShape.lineCap = kCALineCapRound;
maskLayer.lineShape.lineJoin = kCALineJoinRound;
maskLayer.position = self.currentCenter
maskLayer.fillRule = kCAFillRuleEvenOdd
self.mask = maskLayer
}
private func drawTrack(ctx: CGContext) {
let adjustDegree = Math.adjustDegree(self.setting.startAngle, degree: self.degree)
let centerX = self.currentCenter.x
let centerY = self.currentCenter.y
let radius = min(centerX, centerY)
CGContextSetFillColorWithColor(ctx, self.setting.trackingColor.CGColor)
CGContextSetLineCap(ctx, CGLineCap.Round)
CGContextBeginPath(ctx)
CGContextMoveToPoint(ctx, centerX, centerY)
CGContextAddArc(ctx, centerX, centerY, radius,
CGFloat(Math.degreesToRadians(self.setting.startAngle)),
CGFloat(Math.degreesToRadians(adjustDegree)), 0)
CGContextClosePath(ctx);
CGContextFillPath(ctx);
}
最佳答案
如果这是一个形状层,你只需说 myShapeLayer.lineCap = "round"
。 (我对你的蒙版和绘图代码感到困惑,这与形状图层无关,所以我不知道它应该如何适应。)
这是一个带有圆形路径的形状图层:
关于ios - Swift - 如何在 CAShapeLayer 或 UIBezierPath(ovalInRect : ovalRect)) 上获得圆顶,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38689322/