3

我通过子类化 MKAnnotationView 创建了一个自定义注释视图。此类还创建了一个自定义标注(信息弹出“气泡”)视图,该视图的皮肤与我的应用程序相匹配。

我还希望能够重新设置用户位置点的标注气泡,但似乎我对该视图的唯一控制是它是否被完全覆盖,方法是在mapView:viewForAnnotation:方法中使用以下内容:

if(annotation == self.mapView.userLocation)
{
    return nil;
}

但我真正想做的是找出 MapKit 用于用户位置蓝点的注释视图,然后将其子类化,以便我可以为其标注气泡蒙皮......或者还有其他方法吗?还是根本没有办法?

4

3 回答 3

1

I am not sure this will help you, but you can use the default user location annotation view, then steal the view in mapView:didSelectAnnotationView::

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
    if (view == [mapView viewForAnnotation:mapView.userLocation]) {
        // do what you want to 'view'
        // ...
    }
    // ...
}

I have used this trick to change the callout title and subtitle, and add an image using leftCalloutAccessoryView. However, I haven't tried totally replacing the callout, so I don't know if it's possible.

于 2011-10-25T21:14:19.833 回答
0

我认为这是不可能直接的,但你可以在运行时覆盖一些方法: http: //theocacao.com/document.page/266

于 2013-07-03T08:39:15.357 回答
0

您可以使用

if ([annotation isKindOfClass:[MKUserLocation class]]) { // or if(annotation == self.mapView.userLocation)
   MKAnnotationView * annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:@"MyLocation"];
   if (annotationView == nil) {
      annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"MyLocation"] autorelease];
         annotationView.canShowCallout = NO;
         annotationView.image = [UIImage imageNamedWithBrand:@"MyLocationPin.png"];
      } else {
         annotationView.annotation = annotation;
      }
   return annotationView;
}
于 2011-10-24T16:38:45.753 回答