mkmapview MKUserLocation AnnotationView [英] mkmapview MKUserLocation AnnotationView

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

问题描述

我正在尝试为地图上的注释创建自定义注释视图.我通过调整协议MKMapViewDelegate并覆盖函数mapView:viewForAnnotation:来做到这一点.一切正常,唯一的问题是我还将showsUserLocation设置为TRUE,这意味着我在mapView:viewForAnnotation:方法中获得的一个注释"属于类MKUserLocation.

I'm trying to create custom annotationviews for the annotations on my map. I'm doing that by adapting the protocol MKMapViewDelegate and overwriting the function mapView:viewForAnnotation:. It all works, the only problem is that I also have showsUserLocation set to TRUE, which means that one "Annotation" I get in my mapView:viewForAnnotation: method is of the class MKUserLocation.

我不希望用户位置注释具有我的自定义注释视图,我希望该视图显示默认的用户位置注释视图!如何为用户位置返回默认的用户位置注释视图,或者将其排除在注释之外(在mapView:viewForAnnotation:中)?

I don't want the userlocation annotation to have my custom annotationview, I want that one to show the default userlocation annotationview! How do I return the default userlocation annotationview for the userlocation or exclude it from the annotations (that come in mapView:viewForAnnotation:)?

我试图在mapView:viewForAnnotation:方法中捕获UserLocation,但是我不知道返回什么! (在此示例中,我将返回一个标准的MKAnnotationView,但它看起来不像默认的UserLocation注释( 显然 ).)

I have tried to catch the UserLocation in the mapView:viewForAnnotation: method, but I don't know what to return! (In this example I'm returning a standard MKAnnotationView, but that doesn't look like the default UserLocation Annotation (obviously).)

    if (![[annotation class] isEqual:[MKUserLocation class]]) {

        MKAnnotationView *view = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"customAnnotation"];
        // edit the custom view
        return view;
    }

    MKAnnotationView *view = [[MKAnnotationView alloc] init];
    return view;

推荐答案

要显示用户位置的默认注释,对于这种情况,只需返回nil,我就是这样的:

to show the default annotation for user location just return nil for that case, I did it this way:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
    // use your custom annotation
    if ([annotation isKindOfClass:[MyAnnotationClass class]]) {
        ...

        return annotationView;
    }

    // use default annotation
    return nil;
}

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

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