【发布时间】:2020-09-30 17:35:38
【问题描述】:
我的应用中有一个显示用户位置的地图视图。当用户的位置被点击时,图像显示如下:
有没有办法根据我的喜好定制此图像,例如,我想显示用户在他自己的个人资料中拥有的照片,或者我想添加的任何其他静态图像。
类似于苹果地图在您的位置点中显示您的个人资料图片的方式。
我该怎么做?
这是我的代码:
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if annotation is MKUserLocation {
print("user location image tapped")
return nil
}
let reuseId = "pin"
var pinView = mapView.dequeueReusableAnnotationView(withIdentifier: reuseId) as? MKPinAnnotationView
if pinView == nil {
pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
pinView?.animatesDrop = true
pinView?.canShowCallout = true
pinView?.isDraggable = true
// pinView?.pinColor = .purple
let rightButton: AnyObject! = UIButton(type: UIButton.ButtonType.detailDisclosure)
pinView?.rightCalloutAccessoryView = rightButton as? UIView
}
else {
pinView?.annotation = annotation
}
return pinView
}
对此有什么帮助吗?谢谢。
【问题讨论】:
-
您是自己写的还是抄袭的?不要误会我的意思,但有一些我不知道的零控制,你能解释更多细节吗?你为什么使用 MKPinAnnotation 而不是 MKAnnotationView ?
-
因为使用 MKPinAnnotation 我可以弹出窗口,向用户查看 MKAnnotationView 不支持的更多详细信息。但这不是问题所在,您对我的问题有什么不明白的地方?@sekoyaz
-
hmm 然后试试这个,我补充回答会很有帮助@mike
标签: ios swift mkmapview mkannotation mkannotationview