我想在地圖上自定義註釋,而不是針腳,我希望註釋看起來像當前的位置指示器。我將如何做到這一點?任何建議都會很棒!如何使註釋看起來像當前位置指示符?
1
A
回答
1
一般來說,您可以使用擴展MKPointAnnotation的自定義註釋對象。但是,如果你只需要改變圖釘圖像就可以避免子類,只是實現這個方法
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
let identifier = "MyPin"
if annotation.isKindOfClass(MKUserLocation) {
return nil
}
var annotationView = mapView.dequeueReusableAnnotationViewWithIdentifier(identifier)
if let annotationView = annotationView {
annotationView.annotation = annotation
} else {
annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: identifier)
annotationView.image = UIImage(named: "myPinImage")
}
return annotationView
}
所以,這足以讓你找到正確的圖像,並用它替代引腳。 但是,如果你想跟着默認currentLocation圖像可能發生的變化,你可以重複使用默認視圖
let annotationView = mapView.viewForAnnotation(mapView.userLocation());
+0
我得到這個錯誤http://puu.sh/orVH6/065e730604.png – user6032625
+0
@ user6032625 - 他的意思是如果讓'='而不是'=='。 – Rob
相關問題
- 1. 默認顯示當前位置註釋
- 2. 引腳註釋顯示當前位置
- 3. 當前位置的iPhone mapKit註釋
- 4. 當前位置註釋默認外觀?
- 5. 單擊按鈕時,如何使用用戶當前位置顯示註釋?
- 6. 我使用此代碼來查看用戶當前位置。當前位置
- 7. SKMapView(Skobbler)上沒有顯示用戶當前位置註釋 - iOS
- 8. iOS MapView在visibleRect中顯示當前位置和註釋
- 9. 如何在當前位置加載少量註釋?
- 10. 當前位置點看起來很奇怪
- 11. 位置註釋圖像
- 12. Android如何專注於當前位置
- 13. 如何在xcode上使用FLICKR API來顯示當前位置的圖像?
- 14. 設置當前位置註釋的canShowCallOut = NO,iPhone
- 15. HttpRequestMessage如何看起來像?
- 16. 顯示MKMapView以一次顯示多個註釋和當前用戶位置
- 17. PCRE正則表達式看起來像一個註釋的字符串
- 18. 如何在osmdroid中顯示當前位置指針?
- 19. 如何使leftBarButtonItem看起來像backBarButtonItem?
- 20. 如何使UITableView看起來像這樣
- 21. 如何使JTextField看起來像JLabel
- 22. 如何使GtkTextView看起來像GtkEntry?
- 23. 如何使SSIS包看起來像DTS
- 24. 如何使UITableView看起來像這樣?
- 25. 如何使GUI看起來像這樣?
- 26. android gps如何顯示當前位置
- 27. 使用biomaRt註釋位置
- 28. VBScript來從當前位置
- 29. 如何註釋掉當前行?
- 30. 從當前位置到註釋的距離。 (Firebase)
只是一個圓點?爲它創建一個圖像,然後讓'viewForAnnotation'創建一個'MKAnnotationView'並設置它的'image'屬性。 – Rob
請參閱[定義自定義註釋對象](https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/LocationAwarenessPG/AnnotatingMaps/AnnotatingMaps.html#//apple_ref/doc/uid/TP40009497-CH6- SW2)在_Location和地圖編程指南._ – Rob