我正在尝试弄清楚如何使用新的 MKOverlayPathRenderer
类。
在我的应用程序中,我之前在使用 iOS 6 SDK 构建时使用了 MKOverlayPathView
,
但不幸的是,它似乎不适用于 iOS 7 SDK。
所以我试图将我的应用程序从 MKOverlayPathView
移动到
MKOverlayPathRenderer
,但至今没有成功。
MKPolylineRenderer
工作正常,但 MKOverlayPathRenderer
不行。
代码被调用,但没有在 map 上绘制叠加层。
有人有MKOverlayPathRenderer
的工作示例吗?
最佳答案
首先,您必须确保设置了 lineWidth
和 strokeColor
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/