Remove MKAnnotationView Default Callout From View

北战南征 提交于 2019-12-24 06:47:35

问题


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.

来源:https://stackoverflow.com/questions/43766219/remove-mkannotationview-default-callout-from-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!