1

我试图防止 MKMapKit在点击显示在 a 上的标记时显示默认注释标注,MKMapView 而不会阻止注释的委托调用/交互(见下文)。

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

    // Custom callout initialized & presented here
    . . .

}

我了解您可能会禁止该宣传信息完全显示

someAnnotationView.canShowCallout = NO;

或者(更多的是一种骇人听闻的方法)设置注释的任何显示参数:

// Commenting out string assignments below

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

正如其他线程中所建议的那样,向注释视图添加子视图确实会向您选择的边界框架添加自定义视图(无论您喜欢什么)。

然而,问题是添加子视图

  1. 不会阻止默认标注气泡出现
  2. 如果您禁用canShowCallout 不设置标签,注释交互将丢失..
  3. 如果您添加子视图,它会添加到默认标注下方。

3 注意 您可以将添加子视图延迟 +0.5 秒,然后将您的自定义视图添加到标注上方,但这是一个糟糕的解决方法,因为您会看到默认标注在您的视图之前出现。

是否有任何解决方法

  1. 删除默认标注而不禁用调用委托方法,
  2. 或编辑实​​际的标注视图(我猜它是一些CGPathUIBezierePath绘制的视图)

任何帮助,将不胜感激。谢谢!

更新:

我正在使用委托mapView:viewForAnnotation来创建注释视图并将其添加到我的地图中。

4

1 回答 1

0

选中后删除注释的标题和副标题:

    func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
        if let annotation = view.annotation {
            annotation.title = nil
            annotation.subtitle = nil
        }
    }
于 2020-08-17T23:15:52.410 回答