【发布时间】:2017-05-11 16:45:13
【问题描述】:
我想在图钉位置上方显示一个 UIView,如果用户在地图上移动,UIView 应该保持在图钉位置上方。我不想使用标注气泡。还有其他方法吗?
【问题讨论】:
标签: ios swift mkmapview mkannotation mkpointannotation
我想在图钉位置上方显示一个 UIView,如果用户在地图上移动,UIView 应该保持在图钉位置上方。我不想使用标注气泡。还有其他方法吗?
【问题讨论】:
标签: ios swift mkmapview mkannotation mkpointannotation
尝试使用此代码:
func mapView(_ mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView {
if (annotation is MKUserLocation) {
return nil
}
else if (annotation is YourAnnotationClassHere) {
let identifier = "MyCustomAnnotation"
var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier)
if annotationView {
annotationView.annotation = annotation
}
else {
annotationView = MKAnnotationView(annotation, reuseIdentifier: identifier)
}
annotationView.canShowCallout = false
// set to YES if using customized rendition of standard callout; set to NO if creating your own callout from scratch
annotationView.image = UIImage(named: "your-image-here.png")!
return annotationView
}
return nil
}
这主要是你需要它来工作。这是此答案的快速版本:How to create Custom MKAnnotationView and custom annotation title and subtitle
希望对你有帮助!!!
【讨论】:
在 iOS 9 中,我们有一个名为 detailCalloutAccessoryView 的新属性
您可以创建一个视图并设置为
annotationView.detailCalloutAccessoryView = tempView
请查看链接以获取更多详细信息
【讨论】: