ios - 寻找 MKOverlayPathRenderer 示例

标签 ios ios7 mkmapview mapkit mkoverlay

我正在尝试弄清楚如何使用新的 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/

相关文章:

objective-c - 将两个 XIB 连接到一个 ViewController

ios - 将 JSON 从 iOS 发布到 ASP.NET

ios-simulator - iOS 7 模拟器与设备差异?

ios - UIButtonTypeSystem 为 UIControlStateHighlighted 设置背景图像

iphone - MKMapView 经纬度坐标

ios - UICollectionView 随机不显示单元格

iOS - 将 GIF 从 URL 保存到已保存的相册

ios - 带有图层的 iOS 6 上的样式控件是错误的? (来自 iOS7)

ios - MKMapView 在固定索引处覆盖

ios6 - MKMapView NSInvalidArgumentException ios6 中的无效区域崩溃