【发布时间】:2017-10-22 21:06:34
【问题描述】:
我的图钉上有一个注解,用于我的 mapView。在我的注释上,我有一个按钮,我希望能够在用户单击按钮时更改按钮图像(从加号到减号)。我不确定在哪里可以更新。我目前在用户单击图钉时设置了按钮图像。在我重新加载地图之前,图像本身不会更新,但我希望在用户单击它后立即更新注释视图上的按钮。我不确定在弹出注释时如何更新按钮。
func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
if let annotation = view.annotation as? MKPointAnnotation {
let btn = UIButton(type: .detailDisclosure)
view.rightCalloutAccessoryView = btn
if annotation.accessibilityValue! == "Minus" {
let button = UIButton(frame: CGRect(x: 0, y: 0, width: 30, height: 30))
button.setBackgroundImage(UIImage(named: "minus"), for: .normal)
button.addTarget(self, action: #selector(MapVC.minus), for: .touchUpInside)
view.leftCalloutAccessoryView = button
} else {
let button = UIButton(frame: CGRect(x: 0, y: 0, width: 30, height: 30))
button.setBackgroundImage(UIImage(named: "plus"), for: .normal)
button.addTarget(self, action: #selector(MapVC.plus), for: .touchUpInside)
view.leftCalloutAccessoryView = button
}
}
}
【问题讨论】:
标签: ios swift mkmapview mkannotation mkannotationview