Khanh Nguyen
Khanh Nguyen

Reputation: 11134

Custom callout getting dismissed in MKMapView when tapped

I have a map view and a custom callout built from scratch. Everything works fine except that the callout disappears whenever user taps on it.

Upvotes: 0

Views: 216

Answers (1)

Khanh Nguyen
Khanh Nguyen

Reputation: 11134

First, make sure you override pointInside in your custom annotation view to account for the callout:

override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
    if self.bounds.contains(point) {
        return true    
    } else {
        return self.subviews.contains { $0.frame.contains(point) }
    }
}

Then, map view turns out to favour UIButton in a callout and won't dismiss if the tap hits an instance of UIButton. Make sure that you cover the whole callout view with a button (which may or may not do anything when tapped).

You can add subviews into a UIButton, but make sure that they all have isUserInteractionEnabled set to false.

Upvotes: 0

Related Questions