Ios 自定义标注未接收触摸操作

Ios 自定义标注未接收触摸操作,ios,swift,mapkit,mkannotationview,calloutview,Ios,Swift,Mapkit,Mkannotationview,Calloutview,下面是自定义详图索引类 func mapView(mapView: MKMapView!, didSelectAnnotationView view: MKAnnotationView!) { /* * Other stuff .... */ visibleCallOutView = CustomCallOut(frame: aFrame) view.addSubview(visibleCallOutView) } func mapView(mapV

下面是自定义详图索引类

func mapView(mapView: MKMapView!, didSelectAnnotationView view: MKAnnotationView!) {
    /*
     * Other stuff ....
     */
    visibleCallOutView = CustomCallOut(frame: aFrame)
    view.addSubview(visibleCallOutView)
}

func mapView(mapView: MKMapView!, didDeselectAnnotationView view: MKAnnotationView!) {
    visibleCallOutView.removeFromSuperview()
}


所有东西都正常工作,但我无法接收红色按钮的触摸动作。任何建议都是可以接受的。

这是您的@Kampai,由于某种原因,我无法更改代码结构。你能帮我用我的代码解决这个问题吗?这是你的@Kampai,因为某种原因我无法更改代码结构。你能用我的代码帮我解决这个问题吗?。
class CustomCallOut: UIView {
        override init(frame: CGRect) {
            super.init(frame: frame)

            let button = UIButton(frame: bounds)
            button.addTarget(self, action: "callOutButtonTouchAction:", forControlEvents: UIControlEvents.TouchUpInside)
            button.backgroundColor = UIColor.redColor()
            addSubview(button)
        }

        func callOutButtonTouchAction(sender: AnyObject) {
            println("callOutButtonTouchAction called")
        }

        required init(coder aDecoder: NSCoder) {
            fatalError("init(coder:) has not been implemented")
        }

        override func hitTest(var point: CGPoint, withEvent event: UIEvent?) -> UIView? {
            let viewPoint = superview?.convertPoint(point, toView: self) ?? point
            let isInsideView = pointInside(viewPoint, withEvent: event)
            var view = super.hitTest(viewPoint, withEvent: event)
            return view
        }

        override func pointInside(point: CGPoint, withEvent event: UIEvent?) -> Bool {
            return CGRectContainsPoint(bounds, point)
        }
    }