问题
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
- Does not stop the default callout bubble from appearing
- IF you disable
canShowCallout
OR don't set the labels, annotation interaction is lost.. - 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
- Removing the default callout without disabling the delegate method from being called,
- or Editing the actual callout view (I'm guessing it's some
CGPath
orUIBezierePath
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