Ios 如何执行自定义注释视图未找到按钮单击事件?

Ios 如何执行自定义注释视图未找到按钮单击事件?,ios,swift,mapkitannotation,Ios,Swift,Mapkitannotation,我将尝试在自定义批注视图中查找按钮外单击事件。如何做到这一点。在此不查找按钮外单击事件中。请给我一些提示 func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) { let overlays = self.mapVW.overlays self.mapVW.removeOverlays(overlays) if view.annotation is MKUserL

我将尝试在自定义批注视图中查找按钮外单击事件。如何做到这一点。在此不查找按钮外单击事件中。请给我一些提示

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

        let overlays = self.mapVW.overlays
        self.mapVW.removeOverlays(overlays)

        if view.annotation is MKUserLocation
        {
            // Don't proceed with custom callout
            return
        }

        let customeView = view.annotation as! Artwork
        let viewCustome = Bundle.main.loadNibNamed("mapPopUp", owner: nil, options: nil)

        let callOutView = viewCustome![0] as! CustomCalloutView
        callOutView.lblLocationName.text = customeView.title
        callOutView.lblCategory.text = customeView.category
        callOutView.lblDistance.text = customeView.distance

        let button = UIButton(frame: callOutView.lblLocationName.frame)
        button.addTarget(self, action: #selector(GayGuideViewController.btnRouteView(sender:)), for: .touchUpInside)
        callOutView.addSubview(button)

        callOutView.center = CGPoint(x: view.bounds.size.width / 5, y: -callOutView.bounds.size.height*0.52)
        view.addSubview(callOutView)
        mapVW.setCenter((view.annotation?.coordinate)!, animated: true)
    }

提前感谢。

我已经使用hitTest方法在自定义弹出视图中单击事件。我已经找到了生命点,添加了通知观察者并执行了我的动作事件

    class CAnnotationView: MKAnnotationView
        {
            override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
                let hitView = super.hitTest(point, with: event)
                if (hitView != nil)
                {
                    self.superview?.bringSubview(toFront: self)
                }
                return hitView
            }
            override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
                let rect = self.bounds
                var isInside: Bool = rect.contains(point)
                if(!isInside)
                {
                    for view in self.subviews
                    {
                        isInside = view.frame.contains(point)
                        if isInside
                        {
                            let dictionary = NSMutableDictionary()
                            dictionary.setValue(self.annotation?.coordinate.latitude, forKey: "lat")
                            dictionary.setValue(self.annotation?.coordinate.longitude, forKey: "long")

                            NotificationCenter.default.post(name: NSNotification.Name(rawValue: "Noti_Coordinate"), object: nil, userInfo: dictionary as? [AnyHashable : Any])
                            break
                        }
                    }
                }
                return isInside
            }
        }


override func viewDidLoad() 
   {
                 NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: "Noti_Coordinate"), object: nil)
            NotificationCenter.default.addObserver(self, selector: #selector(notificationForRoute(noti:)), name: NSNotification.Name(rawValue: "Noti_Coordinate"), object: nil)
    }
func notificationForRoute(noti : NSNotification)
    {
        let dict = noti.userInfo! as NSDictionary
        let lat = dict.value(forKey: "lat")
        let long = dict.value(forKey: "long")

        let coordinate = CLLocationCoordinate2D(latitude: lat as! CLLocationDegrees, longitude: long as! CLLocationDegrees)

        let overlays = self.mapVW.overlays
        self.mapVW.removeOverlays(overlays)

        route(dest: coordinate )
    }

您是否已将
手势识别器
添加到您的
customeView
?我没有使用手势识别器。我已尝试但未完成@biloshkurskyi.ss究竟是什么问题?单击注释视图是否没有触发调用
didSelect
?(如果是这样,我们必须查看注释视图是如何创建/配置的。)或者调用上的单击没有得到您希望的处理?我已经通过点击测试解决了您的解决方案中给出的问题。谢谢@Rob