Remove MKAnnotationView Default Callout From View

2019-08-05 04:52发布

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.

0条回答
登录 后发表回答