gpt4 book ai didi

ios - MKMapView : can't display stroked ellipse 中的自定义核心图形覆盖

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:51:46 26 4
gpt4 key购买 nike

我正在尝试绘制一系列同心圆作为 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]] );

}
}

请问,我到底应该怎么做才能显示描边图像?

最佳答案

啊啊啊,终于....

答案是在绘制之前需要这样设置线宽:

CGContextSetLineWidth(context, 0.5 * MKRoadWidthAtZoomScale(zoomScale));

不确定为什么会这样,但您不能只为线宽设置任何值。

关于ios - MKMapView : can't display stroked ellipse 中的自定义核心图形覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6912511/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com