【问题标题】:How to show a UIView just above the MKpointAnnotation Pin如何在 MKpointAnnotation Pin 上方显示 UIView
【发布时间】:2017-05-11 16:45:13
【问题描述】:

我想在图钉位置上方显示一个 UIView,如果用户在地图上移动,UIView 应该保持在图钉位置上方。我不想使用标注气泡。还有其他方法吗?

【问题讨论】:

标签: ios swift mkmapview mkannotation mkpointannotation


【解决方案1】:

尝试使用此代码:

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

希望对你有帮助!!!

【讨论】:

  • 由于您还没有发布任何代码,这是我可以帮助您的唯一方法
【解决方案2】:

在 iOS 9 中,我们有一个名为 detailCalloutAccessoryView 的新属性

您可以创建一个视图并设置为

annotationView.detailCalloutAccessoryView = tempView 

请查看链接以获取更多详细信息

MapKit iOS 9 detailCalloutAccessoryView usage

【讨论】:

    猜你喜欢
    • 2014-05-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-11
    相关资源
    最近更新 更多