2016-06-14 36 views
0

我試圖用MKOverlayRenderer繪製線條。我的疊加渲染的drawMapRect大致是:MKOverlayRenderer使用CGPath繪製線條

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)關閉路徑不起作用。

+0

當它確實填滿了所有的東西都在你期望的位置? – Wain

+0

如果我調用'CGContextDrawPath(context,.FillStroke)'它填充多邊形,這是在正確的位置 –

回答

1

我的線寬(2.0)對於縮放級別來說太小了。

+0

這節省了我。需要把它推到400才能看到,因爲我開始了boundingRect MKMapRectWorld –