在 Swift 中显示 MKAnnotationView 的披露指示器标注
Show callout for disclosureindicator for MKAnnotationView in Swift
我可以使用以下代码在我的地图注释中显示披露图标。
annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: annotationIdentifier)
annotationView?.rightCalloutAccessoryView = UIButton(type: .detailDisclosure)
当您按下披露图标时,它会闪烁但没有其他反应。我试着在上面放一个按钮处理程序,但它不是按钮,所以编译器拒绝了。我是否必须创建一个完整的手势识别器才能让它执行任何操作,或者我如何按下指示器以显示有关位置的信息?
试试这个
let btn = UIButton(type: .detailDisclosure)
btn.addTarget(self, action: #selector(btnDisclosureAction(_:)), for: .touchUpInside)
annotationView.rightCalloutAccessoryView = btn
@objc func btnDisclosureAction(_ sender: UIButton) {
// you action
}
你需要这个委托方法
func mapView(_ mapView: MKMapView,
annotationView view: MKAnnotationView,
calloutAccessoryControlTapped control: UIControl)
和
self.mapView.delegate = self
我可以使用以下代码在我的地图注释中显示披露图标。
annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: annotationIdentifier)
annotationView?.rightCalloutAccessoryView = UIButton(type: .detailDisclosure)
当您按下披露图标时,它会闪烁但没有其他反应。我试着在上面放一个按钮处理程序,但它不是按钮,所以编译器拒绝了。我是否必须创建一个完整的手势识别器才能让它执行任何操作,或者我如何按下指示器以显示有关位置的信息?
试试这个
let btn = UIButton(type: .detailDisclosure)
btn.addTarget(self, action: #selector(btnDisclosureAction(_:)), for: .touchUpInside)
annotationView.rightCalloutAccessoryView = btn
@objc func btnDisclosureAction(_ sender: UIButton) {
// you action
}
你需要这个委托方法
func mapView(_ mapView: MKMapView,
annotationView view: MKAnnotationView,
calloutAccessoryControlTapped control: UIControl)
和
self.mapView.delegate = self