有没有办法对用于 MKUserLocation 蓝点的 MKAnnotationView 进行子类化?

发布于 2024-12-12 02:23:23 字数 358 浏览 0 评论 0原文

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

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

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

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

I've created a custom annotation view by subclassing MKAnnotationView. This class also creates a custom callout (info pop-up 'bubble') view which is skinned to match my app.

I also want to be able to reskin the callout bubble for the user location dot, but it seems as though the only control I have over that view is whether it is overridden completely or not, by using the following inside the mapView:viewForAnnotation: method:

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

But what I really want to do is find out what annotation view MapKit is using for the user location blue dot, and then subclass it so I can skin its callout bubble... Or is there another way? Or just no way at all?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

傲鸠 2024-12-19 02:23:23

我不确定这会对您有帮助,但您可以使用默认的用户位置注释视图,然后窃取 mapView:didSelectAnnotationView: 中的视图:

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

我已经使用此技巧来更改标注标题和副标题,并使用 leftCalloutAccessoryView 添加图像。但是,我还没有尝试完全替换标注,所以我不知道这是否可能。

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.

酷到爆炸 2024-12-19 02:23:23

您可以使用

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;
}

You can use

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;
}
墟烟 2024-12-19 02:23:23

我认为直接不可能,但您可以在运行时重写一些方法: http://theocacao. com/document.page/266

I think it is not possible directly, but you can override some methods in runtime with this: http://theocacao.com/document.page/266

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文