iOS MapKit更改mapview maptype会导致注释图像更改为pin吗? [英] iOS MapKit Changing mapview maptype causes annotation image to change to pin?

查看:105
本文介绍了iOS MapKit更改mapview maptype会导致注释图像更改为pin吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关以下问题的任何建议将不胜感激。

Any suggestions on what is wrong with the following would be appreciated.

我使用以下代码将自定义图像添加到注释中。

I am adding a custom image to an annotation using the following code.

- (MKAnnotationView *)mapView:(MKMapView *)mapView 
            viewForAnnotation:(id <MKAnnotation>)annotation
{
    if ([annotation isMemberOfClass:[MKUserLocation class]]) 
    { 
        return nil; 
    } 


    if ([annotation isMemberOfClass:[SpectatorPin class]]) 
    { 
        SpectatorPin *sp = (SpectatorPin *)annotation;
        MKAnnotationView *view = [self.mapView dequeueReusableAnnotationViewWithIdentifier:@"specPin"];
        if (view == nil) {
            view = [[[MKPinAnnotationView alloc] initWithAnnotation:sp reuseIdentifier:@"specPin"] autorelease];
        }
        view.image = [UIImage imageNamed:@"mylocation20x20.png"]; 
        view.canShowCallout = YES;
        view.annotation=annotation;
        return view;
    }

    //Should not get here
    return nil;

}

图像最初显示正确。

我有一个段控件可以改变地图类型(标准,卫星,混合)。标准是默认值。一旦我选择卫星,图像立即变为一个引脚。不会再次调用mapView:viewforAnnotation方法。

I have a segment control which changes the map type (standard, satellite, hybrid). Standard is the default. As soon as I select satellite the image immediately changes to a pin. The mapView:viewforAnnotation method is not called again.

问候,

Jim

推荐答案

对于自定义图像,您可以使用MKAnnotationView而不是MKPinAnnotationView。

For custom image, you might use MKAnnotationView instead of MKPinAnnotationView.

MKAnnotationView *view = [self.mapView dequeueReusableAnnotationViewWithIdentifier:@"specPin"];
        if (view == nil) {
            view = [[[MKAnnotationView alloc] initWithAnnotation:sp reuseIdentifier:@"specPin"] autorelease];
        }

这篇关于iOS MapKit更改mapview maptype会导致注释图像更改为pin吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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