【发布时间】:2018-04-30 09:46:48
【问题描述】:
我正在尝试根据注释包含的值更改MKMarkerAnnontationView 的图像。所有注释都使用此代码获得相同的图像,我需要根据用户选择的值以某种方式设置图像。因此,当用户按下另一种类型的停车时,使用的是同一个对象,但使用了另一种类型。
我试图强制重新加载注释,但我没有让它工作。有什么可以帮我的吗?
if let dequeuedView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier) as? MKMarkerAnnotationView {
dequeuedView.annotation = annotation
view = dequeuedView
} else {
view = MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: identifier)
view.canShowCallout = true
view.glyphTintColor = UIColor.white
view.calloutOffset = CGPoint(x: -5, y: 5)
if annotation.type == .bus {
view.glyphImage = UIImage(named: "bus")
} else if annotation.type == .disabled {
view.glyphImage = UIImage(named: "disabled")
} else if annotation.type == .MC {
view.glyphImage = UIImage(named: "mc")
}
}
return view
}
return nil
}
【问题讨论】:
-
你可以在 if else 块之前添加 debugPrint(annotation.type) 并确保类型不同吗?
标签: ios swift maps mapkit mkannotation