繁体   English   中英

根据注释的属性设置注释的字形文本

[英]Set annotation's glyphtext based on the annotation's properties

我遇到了自定义注释显示不正确的问题。 在我的代码中,我检查当前注释是否针对具有给定唯一标识符的电台。 如果是这样,我会自定义其属性。

StationAnnotationView.swift

class StationAnnotationView: MKMarkerAnnotationView {

override var annotation: MKAnnotation? {
    willSet {
        guard let station = newValue as? Station else { return }

        clusteringIdentifier = nil
        displayPriority = .required

        if (station.id == "26") {
                glyphText = "p"
                markerTintColor = UIColor(named: "Blue")
        }
    }
}

起初,我的mapView正确显示注释(即,更改唯一具有station.id == 26站的颜色和字形文本),但是在平移和缩放一段时间后,我的自定义格式开始应用于其他注释(这不应该发生,因为任何给定的station.id只有一个站)。 我怀疑这是由于AnnotationView重用了注释。 我怎样才能防止这种情况发生?

正如您所说,这是由于 AnnotationView 重用了注释。 试试下面的代码:

    if (station.id == "26") {
            glyphText = "p"
            markerTintColor = UIColor(named: "Blue")
    } else {
            glyphText = // Default text
            markerTintColor = // Default color
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM