【问题标题】:Hide, show annotation on MkMapView在 MkMapView 上隐藏、显示注释
【发布时间】:2010-01-20 10:08:52
【问题描述】:

缩小地图视图时如何隐藏注释。我有大量注释,我必须隐藏它们,因为如果地图上显示的区域太大,您只能看到注释。

【问题讨论】:

    标签: iphone objective-c cocoa cocoa-touch iphone-sdk-3.0


    【解决方案1】:

    为此,您必须检查您所在区域的大小,并根据它设置视图是否隐藏。

    我测试了下面的代码,但是您可能需要进行一些调整。

    
    - (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
    {
        NSArray *annotations = [_mapView annotations];  
        MyAnnotation *annotation = nil; 
        for (int i=0; i<[annotations count]; i++)
        {
            annotation = (MyAnnotation*)[annotations objectAtIndex:i];
            if (_mapView.region.span.latitudeDelta > .010)
            {
                [[_mapView viewForAnnotation:annotation] setHidden:YES];
            }
            else {
                [[_mapView viewForAnnotation:annotation] setHidden:NO];
            }
        }
    }
    

    【讨论】:

    • 感谢支持。+1
    • 2022 年仍然有效 :-)!
    【解决方案2】:

    Swift 版本:

    let annotations = self.maps.annotations
    
        for annotation in annotations
        {
            if (self.maps.region.span.latitudeDelta > 0.010)
            {
    
                self.maps.viewForAnnotation(annotation)?.hidden = true
    
            }
            else {
    
                self.maps.viewForAnnotation(annotation)?.hidden = false
    
            }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-09-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-05
      • 1970-01-01
      相关资源
      最近更新 更多