寻找MKOverlayPathRenderer示例 [英] Looking for an MKOverlayPathRenderer example

查看:334
本文介绍了寻找MKOverlayPathRenderer示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想弄清楚如何使用新的 MKOverlayPathRenderer 类。

I am trying to figure out how to use a new MKOverlayPathRenderer class.

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

In my app I previously used MKOverlayPathView when building with iOS 6 SDK, but it does not seem to work with iOS 7 SDK unfortunately.

所以我试图将我的应用从 MKOverlayPathView 移到
MKOverlayPathRenderer ,但没有到目前为止成功。

So I am trying to move my app from MKOverlayPathView to MKOverlayPathRenderer, but have no success so far.

MKPolylineRenderer 工作正常,但 MKOverlayPathRenderer 没有。
代码被调用,但地图上没有绘制叠加。

MKPolylineRenderer works OK, but MKOverlayPathRenderer does not. The code gets called, but no overlay is drawn on a map.

是否有人有 MKOverlayPathRenderer的工作示例

推荐答案

首先,你必须确保设置 lineWidth strokeColor

First you have to make sure that you set lineWidth and strokeColor

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

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

Then In your renderer class, you have to override -(void) createPath method

-(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.
}

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

if you want custom drawing, you would like to override this

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

这篇关于寻找MKOverlayPathRenderer示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆