首页 > 解决方案 > Swift Annotation Pin 的 Calloutbubble 手势

问题描述

我正在寻找将手势添加到注释引脚的标注气泡的答案。

我尝试了不同的解决方案,但它们对我不起作用。

这是最新的:

func mapView(mapView: MKMapView, didSelectAnnotationView view: MKAnnotationView{
    let rightButton = UIButton(type: UIButtonType.detailDisclosure)
    let gesture = UITapGestureRecognizer(target: self, action: #selector(callout(gesture:)))
    rightButton.addGestureRecognizer(gesture)   
    view.rightCalloutAccessoryView = rightButton
}

@objc func callout(gesture: UITapGestureRecognizer){
    print("tapped")
}

标签: iosswift

解决方案


正确的委托方法

func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
    ///
}

self.mapView.delegate = self

推荐阅读