2
我想繪製一系列同心圓作爲MKMapView中的自定義覆蓋。請注意,出於性能原因,我需要實現自定義繪製方法,而不是簡單地添加一系列MKCircleView。MKMapView中自定義核心圖形覆蓋:無法顯示描邊橢圓
我有下面的代碼,我不知道爲什麼我可以看到圓圈,如果他們被填充,但當我只是試圖繪製空白圓圈(即筆畫大綱只),我什麼都看不到。
- (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context {
// draw series of concentric circles
// I have tried all manner of line widths
CGContextSetLineWidth(context, 5.0);
CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor);
CGContextSetStrokeColorWithColor(context, [UIColor yellowColor].CGColor);
float radius;
for (int i = 1; i < self.numberOfRings+1; i++) {
// code to calculate the radius here using i
// but this is fine, set to 1000 metres
radius = 1000.0;
// centre of circles
CLLocationCoordinate2D centre = {latitude: self.latitude, longitude: self.longitude};
// create circle of appropriate geographical dimensions
MKCircle *circle = [MKCircle circleWithCenterCoordinate:centre radius:radius];
// the next two lines don't work, I don't see anything drawn
CGContextStrokeEllipseInRect(context, [self rectForMapRect:[circle boundingMapRect]]);
CGContextStrokePath(context);
// but the dimensions of the rect are ok, because I see the filled in rect (below) perfectly if I uncomment this next line
// CGContextFillEllipseInRect(context, [self rectForMapRect:[circle boundingMapRect]]);
}
}
請問,我該怎麼做才能讓描邊的圖像顯示?
Ahhhh,最後(但是SO不會讓我回答這個問題還有8個小時)......答案是在繪製之前需要像這樣設置線寬:'CGContextSetLineWidth(context,0.5 * MKRoadWidthAtZoomScale(zoomScale));' – John