从视图中删除MKAnnotationView默认标注 [英] Remove MKAnnotationView Default Callout From View
问题描述
我正在尝试 MKMapKit ,以防止在点击 MKMapView上显示的标记时显示默认注释标注代码> 无 阻止委托调用/注释的交互(见下文).
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.
问题是添加子视图
- 不阻止默认标注气泡的出现
- 如果,您禁用了
canShowCallout
或,请不要设置标签,否则注释交互会丢失.. - 如果,您添加了一个子视图,它会被添加到下方默认的标注中.
- 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注意您可以将添加子视图的时间延迟+0.5秒,这将在上方添加自定义视图,但是这是一个很差的解决方法,因为您会看到默认的标注早于您的视图.
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..
是否有任何解决方法
- 删除默认标注,而不会禁止调用委托方法,
- 或编辑实际的标注视图(我猜它是某些
CGPath
或UIBezierePath
绘制的视图)
- 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!
更新:
我正在使用委托 mapView:viewForAnnotation
创建和向我的地图添加注释视图.
I am using the delegate mapView:viewForAnnotation
to create and add annotation views to my map.
推荐答案
选中后,同时删除注释的标题和副标题:
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
}
}
这篇关于从视图中删除MKAnnotationView默认标注的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!