1
votes

I am trying to prevent MKMapKit from presenting the default annotation callout when tapping on a marker displayed on a MKMapView without blocking the delegate call / interaction of the annotation (seen below).

- (void)mapView:(MKMapView *)mapView didSelectAnnotation:(MKAnnotationView *)view {

    // Custom callout initialized & presented here
    . . .

}

I understand you may disable the callout from showing entirely

someAnnotationView.canShowCallout = NO;

or (more of a hackish approach) not setting any display parameters of the annotation:

// Commenting out string assignments below

// someAnnotation.title = @"Hey!";
// someAnnotation.subTitle = @"Aren't I an annoying callout :P ?";

As suggested in other threads, adding a subview to the annotation view does indeed add a custom view (whatever you please) to a bounding frame of your choice.

THE ISSUES, however, are that adding a subview

  1. Does not stop the default callout bubble from appearing
  2. IF you disable canShowCallout OR don't set the labels, annotation interaction is lost..
  3. IF you add a subview, it gets added below the default callout.

3 NOTE You can delay the addition of your subview by +0.5 seconds, which then will add your custom view above the callout, but this is a poor workaround as you see the default callout come into view well before yours..

Is there any workaround for either

  1. Removing the default callout without disabling the delegate method from being called,
  2. or Editing the actual callout view (I'm guessing it's some CGPath or UIBezierePath drawn view)

Any help would be appreciated. Thanks!

Update:

I am using the delegate mapView:viewForAnnotation to create and add annotation views to my map.

1
Are you implementing viewFor annotation:? I've only taken a cursory look at MapKit, but "The annotation view to display for the specified annotation or nil if you want to display a standard annotation view." looks like that's what you want ... developer.apple.com/reference/mapkit/mkmapviewdelegate/…DonMag
@DonMag yes - taking advance (perhaps not the most advantageous way for my case) of the viewFor method to handle adding annotations. Not sure how to go from here in still allowing touch interactionsWill Von Ullrich
Ah... a little more investigating (for my information)... Seems viewFor annotation is the view that shows on the map - such as a "Pin" image. The "callout view" is what shows when you tap the "Pin". This SO question may be helpful... stackoverflow.com/questions/15241340/…DonMag
Right. Looks like the setAnnotation method can help override drawing / setting the callout. More specifically with the post you reference (one I viewed already) stackoverflow.com/a/29594428/4577249 this helped point me in the right direction in setting a completely custom calloutWill Von Ullrich

1 Answers

0
votes

When selected remove both title and subtitle of the annotation:

    func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
        if let annotation = view.annotation {
            annotation.title = nil
            annotation.subtitle = nil
        }
    }