寻找一个MKOverlayPathRenderer的例子
我想弄清楚如何使用一个新的MKOverlayPathRenderer
类。
在我的应用程序中,我以前在使用iOS 6 SDK进行MKOverlayPathView
时使用了MKOverlayPathView
,但不幸的是,它似乎不适用于iOS 7 SDK。
所以我试图将我的应用程序从MKOverlayPathView
移动到MKOverlayPathRenderer
,但迄今为止没有成功。
MKPolylineRenderer
工作正常,但MKOverlayPathRenderer
不。 代码被调用,但是在地图上没有绘制覆盖图。
有没有人有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
方法。