【问题标题】:iOS MapKit Changing mapview maptype causes annotation image to change to pin?iOS MapKit更改mapview maptype会导致注释图像更改为pin?
【发布时间】:2011-07-06 07:13:56
【问题描述】:

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

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

- (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 方法不再被调用。

问候,

吉姆

【问题讨论】:

    标签: ios uiimage mapkit mkannotation mkannotationview


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:
      【解决方案3】:

      试试这个:

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

      【讨论】:

        猜你喜欢
        • 2011-11-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-12-23
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多