Post

Replies

Boosts

Views

Activity

Reply to `onTapGesture` not triggered on `Map` views
Thanks so much for that suggestion, @DTS Engineer! That approach does indeed fire the callback for a tap. But in my particular case, I need the screen coordinate of the tap, and I don't see a way to get that using TapGesture().onEnded {}. However, I found that SpatialTapGesture does provide the screen coordinate of the tap. Here's what this workaround looks like applied to the code sample from the OP: import MapKit import SwiftUI struct ContentView: View { @State private var location = CGPoint.zero var body: some View { Map() .simultaneousGesture(SpatialTapGesture() .onEnded { event in self.location = event.location } ).safeAreaInset(edge: .bottom) { VStack(alignment: .center) { Text("iOS \(UIDevice.current.systemVersion)") .font(.largeTitle) Text("Tapped Location") Text("\(location.x), \(location.y)") } .frame(maxWidth: .infinity, alignment: .center) .background(.background) } } } That seems to work well in my testing! I'll adopt this workaround for now. Thanks for your help! Docs: https://developer.apple.com/documentation/swiftui/tapgesture https://developer.apple.com/documentation/swiftui/spatialtapgesture
Topic: UI Frameworks SubTopic: SwiftUI Tags:
1w
Reply to `onTapGesture` not triggered on `Map` views
FYI: I tested this using the new releases published today, and this issue still exists. Specifically, I observed the issue when: Developing in Xcode beta 6 (17A5305f) running iOS 26 SDK beta 6 (23A5324a) in the simulator Running the sample app on a physical iPhone running iOS 26 beta 7 (23A5326a)
Topic: UI Frameworks SubTopic: SwiftUI Tags:
2w