2
MKMapView内にカスタムオーバーレイとして一連の同心円を描画しようとしています。パフォーマンス上の理由から、一連のMKCircleViewsを単に追加するのではなく、カスタム描画メソッドを実装する必要があることに注意してください。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]]);
}
}
、地球上のどのような私は表示するようにストロークの画像を取得するために行うことになっていますしてください?
最後に(しかし、これで私はこれを8時間も返せません)答えは描画の前に線の幅を設定する必要があるということです: 'CGContextSetLineWidth(context、0.5 * MKRoadWidthAtZoomScale(zoomScale)); ' – John