gpt4 book ai didi

ios - 寻找 MKOverlayPathRenderer 示例

转载 作者:可可西里 更新时间:2023-11-01 03:30:03 25 4
gpt4 key购买 nike

我正在尝试弄清楚如何使用新的 MKOverlayPathRenderer 类。

在我的应用程序中,我之前在使用 iOS 6 SDK 构建时使用了 MKOverlayPathView,但不幸的是,它似乎不适用于 iOS 7 SDK。

所以我试图将我的应用程序从 MKOverlayPathView 移动到MKOverlayPathRenderer,但至今没有成功。

MKPolylineRenderer 工作正常,但 MKOverlayPathRenderer 不行。代码被调用,但没有在 map 上绘制叠加层。

有人有MKOverlayPathRenderer 的工作示例吗?

最佳答案

首先,您必须确保设置了 lineWidthstrokeColor

polylineRenderer.lineWidth = 8.0f;
polylineRenderer.strokeColor = [UIColor redColor];

然后在您的渲染器类中,您必须覆盖 -(void) createPath 方法

-(void) createPath{
CGMutablePathRef path = CGPathCreateMutable();
BOOL pathIsEmpty = YES;
for (int i=0;i< polyline.pointCount;i++){
CGPoint point = [self pointForMapPoint:polyline.points[i]];
if (pathIsEmpty){
CGPathMoveToPoint(path, nil, point.x, point.y);
pathIsEmpty = NO;
} else {
CGPathAddLineToPoint(path, nil, point.x, point.y);
}
}

self.path = path; //<—— don't forget this line.
}

如果你想要自定义绘图,你想覆盖它

-(void) drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context 方法。

关于ios - 寻找 MKOverlayPathRenderer 示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19941200/

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