gpt4 book ai didi

ios - MKAnnotationView : have texts below the annotationView and render the View

转载 作者:行者123 更新时间:2023-11-30 11:21:38 27 4
gpt4 key购买 nike

当我子类化 MKMarkerAnnotationView 时,我可以免费在 MarkerView 下方获得这些漂亮的文本,显示标题和副标题。

当我子类化MKAnnotationView时,我可以完全自由地渲染annotationView:

internal final class POIClusterView: MKAnnotationView {

override var annotation: MKAnnotation? {
willSet {
// render
let renderer = UIGraphicsImageRenderer(size: CGSize(width: 40, height: 40))
self.image = renderer.image { _ in

...
}
}
}

这很好用。但它不像MKMarkerAnnotationView那样在下面显示标题和副标题。

如果我子类化 MKMarkerAnnotationView 并渲染我自己的图像,我会得到下面的这些文本,但 MKMarkerAnnotationView 气泡显示在我自己的图像顶部。

如何才能两者兼得:渲染我自己的图像并免费获取下面的文本?

最直接的想法可能是以某种方式关闭 MKMarkerAnnotationView 气泡的渲染,但我该怎么做?

最佳答案

经过一些实验,我找到了一个简单的解决方案

// Inherit from MKMarkerAnnotationView to get the texts below the annotation for free
class POIMarkerClusterView: MKMarkerAnnotationView {
override var annotation: MKAnnotation? {
willSet {
if let cluster = newValue as? MKClusterAnnotation {
// set properties as usual
// MKMarkerAnnotationView renders title and subtitle in the callout view
// and below the image if and where there is space:
cluster.title = firstPoi.title
if sortedPOIs.count == 2 {
cluster.subtitle = sortedPOIs.last?.title
} else {
// default: MapKit shows something like "+2 more" and localizes it for us
}

// calculate statistics to render

// render own image
self.image = POIClusterImage(cityModel: cityModel, poiStatistics: poiStatistics, count: count)

// MKMarkerAnnotationView's default rendering usually hides our own image.
// so we make it invisible:
self.glyphText = ""
self.glyphTintColor = UIColor.clear
self.markerTintColor = UIColor.clear

}
}
}
}

关于ios - MKAnnotationView : have texts below the annotationView and render the View,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51212796/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com