隐藏地图注释而不删除它们

发布于 2024-08-21 00:57:58 字数 117 浏览 1 评论 0原文

使用 MKMapView,我加载了一堆注释,并且我希望能够过滤使用分段控件显示的注释。

我使用带有类型变量的自定义注释,这样我就可以将它们彼此区分开来,但我无法找到一种方法来随意隐藏和显示注释视图的子集。

Using a MKMapView I have a pile of annoatations loaded onto it and I want to be able to filter the annotations displayed with a segmented control.

I'm using custom annotations with a type variable so I can tell them apart from one another but I haven't been able to find a way to hide and display a subset of annotation views at will.

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

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

发布评论

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

评论(2

面犯桃花 2024-08-28 00:57:58

当然,试试这个:

Objective-C 解决方案:

[[yourMapView viewForAnnotation:yourAnnotation] setHidden:YES]

Swift 4 解决方案:

yourMapView.view(for: yourAnnotation)?.isHidden = true

这将返回与指定注释对象关联的视图,然后您可以将视图设置为隐藏。这是 文档

Sure, try this:

Objective-C solution:

[[yourMapView viewForAnnotation:yourAnnotation] setHidden:YES]

Swift 4 solution:

yourMapView.view(for: yourAnnotation)?.isHidden = true

This will return you the view associated with the specified annotation object, then you can set the view to hidden. Here is the documentation.

本宫微胖 2024-08-28 00:57:58

如果您想隐藏 MKAnnotationView(气泡),您可以创建一个自定义视图:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{

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


    MKAnnotationView *annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"loc"];
    if([annotation isKindOfClass:[AnnotationCustomClass class]] ) {
        annotationView.canShowCallout = NO; // <- hide the bubble

    }

    return annotationView;

}

if you want to hide the MKAnnotationView (bubble) you can create a custom one:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{

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


    MKAnnotationView *annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"loc"];
    if([annotation isKindOfClass:[AnnotationCustomClass class]] ) {
        annotationView.canShowCallout = NO; // <- hide the bubble

    }

    return annotationView;

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