我正在尝试让 SwiftUI
+ MapKit
+ LongPress
手势正常工作。当我在 ContentView
中添加 map 时,效果很好。然后,我将 .onLongPressGesture
修改器添加到 map 中,平移/缩放停止工作。长按还是可以的。
我正在处理的代码:
Map(coordinateRegion: $region, interactionModes: .all, showsUserLocation: true)
.onLongPressGesture {
// How do I get the location (Lat/Long) I am pressed on?
print("onLongPressGesture")
}
另外,有没有办法从长按手势获取纬度/经度?
希望仅使用 SwiftUI
使其工作,而不将 UIKit
包装在 UIViewRepresentable
中。
最佳答案
不要问为什么,但这似乎有效:
Map(coordinateRegion: $region, interactionModes: .all, showsUserLocation: true)
.gesture(DragGesture())
.onLongPressGesture {
print("Here!")
}
关于swiftui - 有人可以使用 SwiftUI+MapKit+LongPress 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71399626/