【发布时间】:2017-02-07 16:47:39
【问题描述】:
我目前正在使用此功能删除可重复使用的引脚:
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView?{
guard !(annotation is MKUserLocation) else { return nil }
let reuseId = "pin"
var pinView = mapView.dequeueReusableAnnotationView(withIdentifier: reuseId) as? MKPinAnnotationView
if pinView == nil {
pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
}
pinView?.pinTintColor = UIColor.orange
pinView?.canShowCallout = true
let smallSquare = CGSize(width: 30, height: 30)
let button = UIButton(frame: CGRect(origin: CGPoint.zero, size: smallSquare))
button.setTitle("Test", for: UIControlState())
button.addTarget(self, action: #selector(triggerConfirmedLocation), for: .touchUpInside)
pinView?.leftCalloutAccessoryView = button
pinView?.rightCalloutAccessoryView = button
return pinView
}
目前用户必须点击图钉才能看到注释;但是,我需要在删除 pin 时打开注释。
我试过这些方法:
pinView?.isSelected = true
和
mapView.selectedAnnotations(reuse, animated: true)
但是第一种方法什么都不做。
第二种方法的错误是 "不能调用非函数类型'[MKAnnotation]'的值"
【问题讨论】:
-
澄清点:听起来您希望打开 callout 视图。注释视图是引脚。
标签: ios swift mkmapview mkannotationview