2011-11-29 52 views

回答

15

有上標註視圖可以更改,一旦用戶的位置已經被更新的屬性:

+0

有時無法確定位置,MKUserLocation變爲灰色。在這種情況下,標註仍在顯示。這個答案不正確。 – Andy

+0

單獨做這件事對我來說不適用於iOS 10.在'viewForAnnotation'中的處理工作。 –

12

您可以設置title爲空白打壓標註:

mapView.userLocation.title = @""; 


編輯:
一個更可靠的方式可能是空白標題中didUpdateUserLocation委託方法:

-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation 
{ 
    userLocation.title = @""; 
} 

viewForAnnotation

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>) annotation 
{ 
    if ([annotation isKindOfClass:[MKUserLocation class]]) 
    { 
     ((MKUserLocation *)annotation).title = @""; 
     return nil; 
    } 

    ... 
} 

在委託方法中設置標題可以讓您確定您有一個真正的userLocation實例可以使用。

+0

謝謝!我知道我可以更改標題和副標題,但不知道將標題設置爲空白字符串會抑制它。 – charudatta

+0

通過@jowie回答更好。改爲使用該方法。 – Anna

+0

@Anna一直在擺弄,但沒有取得成功 - 關於如何在不阻止'mapView:didSelectedAnnotationView:'被調用的情況下完全抑制默認標註泡泡(如上所述,是的,@jowie的答案可能更好)的任何想法? –

0

我有兩個方法可以幫助你:

  1. 抑制mapViewDidFinishLoadingMap

    func mapViewDidFinishLoadingMap(_ mapView: MKMapView) { 
    mapView.showsUserLocation = true 
    //suppress the title 
    mapView.userLocation.title = "My Location" 
    //suppress other params 
    

    }

  2. 抑制didUpdate

    func mapView(_ mapView: MKMapView, didUpdate userLocation: MKUserLocation) { 
        //suppress the title 
        mapView.userLocation.title = "My Location" 
        //suppress other params 
    } 
    
0

斯威夫特4

// MARK: - MKMapViewDelegate 

func mapViewDidFinishLoadingMap(_ mapView: MKMapView) { 
    if let userLocationView = mapView.view(for: mapView.userLocation) { 
     userLocationView.canShowCallout = false 
    } 
} 
相關問題