1
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()
}

Below is the custom callout class

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)
        }
    }

enter image description here

Every thing is working as it should be but I am not able to receive the touch action of the red button. Any suggestion will be appreciable.

Tapas Pal
  • 7,073
  • 8
  • 39
  • 86
  • Here is your [**answer**](http://stackoverflow.com/questions/27519517/button-action-in-mkannotation-view-not-working/27519673#27519673) – Kampai Sep 09 '15 at 05:56
  • @Kampai At that point I am not able to change the code structure for some reason. So can you help me to resolve this with my code? – Tapas Pal Sep 15 '15 at 11:52
  • [Please check this answer](https://stackoverflow.com/questions/28461487/how-to-handle-taps-on-a-custom-callout-view/47607357#47607357). – Gurjinder Singh Dec 02 '17 at 11:29

0 Answers0