我正在尝试弄清楚如何使用新的MKOverlayPathRenderer类。
在我的应用程序中,我之前在使用iOS 6SDK构建时使用了MKOverlayPathView,但不幸的是,它似乎不适用于iOS 7SDK。
因此,我正在尝试将我的应用程序从MKOverlayPathView迁移到MKOverlayPathRenderer,但到目前为止还没有成功。
MKPolylineRenderer可以正常工作,但MKOverlayPathRenderer不能。代码会被调用,但不会在地图上绘制覆盖图。
有没有人有MKOverlayPathRenderer的实用示例
发布于 2013-11-25 17:13:27
首先,您必须确保设置了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方法。
https://stackoverflow.com/questions/19941200
复制相似问题