MKMapView内のカスタムオーバーレイとして一連の同心円を描画しようとしています。パフォーマンス上の理由から、一連のMKCircleViewを単に追加するのではなく、カスタムの描画メソッドを実装する必要があることに注意してください。
次のコードがあり、円が塗りつぶされているとなぜ円が表示されるのかわかりませんが、空の円を描画しようとすると(つまり、ストロークの輪郭のみ)、何も表示されません。
- (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]] );
}
}
ストローク画像を表示するには、一体何をすればよいのでしょうか。