【问题标题】:How can I detect when a MapMarker is clicked/tapped? [duplicate]如何检测何时单击/点击 MapMarker? [复制]
【发布时间】:2021-08-25 21:18:30
【问题描述】:

我正在构建一个 swiftui 应用程序并尝试实现位置搜索视图。我目前将搜索结果显示为注释,并希望用户能够通过点击它们来选择它们。

这可能吗,因为注释不是视图,我不能使用手势修饰符来解决问题。

【问题讨论】:

    标签: swiftui mapkit


    【解决方案1】:

    我找到了一种使用系统样式的方法。 apple developer forum thread 让我意识到用于 MapMarker 的图像可用作系统符号/在 sf 符号中,所以这是我想出的实现。

    MapAnnotation(coordinate: result.coordinate) {
                        Button {
                            selectedDestination = result
                        } label: {
                            Image(systemName: result == selectedDestination ? "mappin.circle.fill" : "mappin.circle")
                        }
                    }
    

    Image的大小和前景色还是要调整的,但原则上是可以的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-08
      • 2015-01-13
      • 1970-01-01
      • 2013-10-08
      • 2011-11-21
      相关资源
      最近更新 更多