我正在尝试让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
仅使用即可工作,而不包含UIKit
在UIViewRepresentable
.