MKOverlayRenderer使用CGPath绘制线条

时间:2016-06-14 07:07:46

标签: ios swift core-graphics mkoverlay

我正在尝试使用MKOverlayRenderer绘制一条线。我的叠加渲染器的drawMapRect大致为:

let path = CGPathCreateMutable()
CGPathMoveToPoint(path, nil, x, y) // x, y = starting point

let remainingPoints: [CGPoint] = ... // remaining points
CGPathAddLines(path, nil, remainingPoints, remainingPoints.count)

CGContextAddPath(context, path)

CGContextSetStrokeColorWithColor(context, UIColor.blueColor().CGColor)
CGContextSetLineWidth(context, 2.0)

CGContextStrokePath(context)

然而,这不起作用,什么都没有出现。我也试过抚摸:

CGContextDrawPath(context, .Stroke)

我知道我的路径定义正确,因为如果我使用.FillStroke,它会填充多边形。

使用CGPathCloseSubpath(path)关闭路径无济于事。

1 个答案:

答案 0 :(得分:1)

我的线宽(2.0)对于缩放级别来说太小了。