2016-07-31 59 views
2

我有这2个功能波纹管在我的课延伸CAShapeLayer,但我不能得到与圆形端的圆弧帽每次我绘制的路径时。它看起来总是像这样的画面:斯威夫特 - 如何获得圆形帽上CAShapeLayer或UIBezierPath(ovalInRect:ovalRect)

enter image description here

我已经使用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); 
    } 

回答

2

如果这是一个形状图层,那么您只需说myShapeLayer.lineCap = "round"。 (我被你的面具迷惑了,并且画出了与形状层无关的代码,所以我不明白它应该如何适应。)

这是一个带有圆形路径的形状图层:

enter image description here

+6

你不应该真正使用定义的常量(kCALineJoinRound,在这种情况下),而不是文本字符串“圆”? –

+0

@DuncanC我做了什么,头告诉我这样做。有效。我停下了。 – matt

+0

你介意张贴代码在这里,红色的圆圈? –