MKMapView 中的自定义核心图形叠加:无法显示描边椭圆
我正在尝试绘制一系列同心圆作为 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]] );
}
}
请问,我到底该怎么做才能显示描边图像?
I'm trying to draw a series of concentric circles as a custom overlay within a MKMapView. Please note that for performance reasons, I need to implement a custom draw method, not simply add a series of MKCircleViews.
I have the following code, and I have no idea why I can see the circles if they are filled, but when I just try to draw empty circles (i.e. stroke outline only), I see nothing.
- (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]] );
}
}
Please, what on earth am I supposed to do to get the stroked images to display?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
啊啊,最后......
答案是,在绘制之前需要像这样设置线宽:
不知道为什么会出现这种情况,但你不能只为线宽设置任何值。
Ahhhh, finally....
The answer is that the line width needs to be set like this prior to drawing:
Not sure why this is the case and you can't just set any value for the line width though.