我试图在MKMapView中绘制一系列同心圆作为自定义覆盖。请注意,出于性能原因,我需要实现一个自定义绘制方法,而不是简单地添加一系列MKCircleViews。
我有以下代码,我不知道为什么我可以看到圆圈,如果他们被填充,但是当我只是尝试画空圆圈(即笔画轮廓),我什么也看不到。
- (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]] );
}
}
请问,我到底该怎么做才能让描边的图像显示出来?
啊,终于....
答案是,在绘制之前需要像这样设置线宽:
CGContextSetLineWidth(context, 0.5 * MKRoadWidthAtZoomScale(zoomScale));
不知道为什么会出现这种情况,而且你不能为行宽设置任何值。