有人可以使用 SwiftUI+MapKit+LongPress 吗?

tom*_*rth 3 gesture mapkit swiftui

我正在尝试让SwiftUI+ MapKit+LongPress手势正常工作。当我在 中添加地图时ContentView,效果很好。然后,我将.onLongPressGesture修改器添加到地图中,平移/缩放停止工作。长按虽然有效。

我正在处理的代码:

Map(coordinateRegion: $region, interactionModes: .all, showsUserLocation: true)
  .onLongPressGesture {
    // How do I get the location (Lat/Long) I am pressed on?
    print("onLongPressGesture")
  }
Run Code Online (Sandbox Code Playgroud)

另外,有没有办法从长按手势中获取纬度/经度?

希望使其SwiftUI仅使用即可工作,而不包含UIKitUIViewRepresentable.

Chr*_*isR 5

不要问为什么,但这似乎有效:

    Map(coordinateRegion: $region, interactionModes: .all, showsUserLocation: true)
        .gesture(DragGesture())
        .onLongPressGesture {
            print("Here!")
        }
Run Code Online (Sandbox Code Playgroud)