Get coordinates of tap when button tapped

I thought this would be a simple Google search! All I want is the X,Y position of the tap when the user taps a button. I want to find out where in the button the user tapped (high or low) so I can position a symbol in the correct spot relative to where the user tapped.

Your my hero of the day if you have the answer (not a hack!).

When I googled “get position of tap swiftui” this article came up, which looks like what you want.

https://www.hackingwithswift.com/quick-start/swiftui/how-to-detect-the-location-of-a-tap-inside-a-view

Also this article Get tap location in SwiftUI.

1 Like

Thank you so much for the response. I did see these articles, unfortunately this works great for shapes but not for a Button. I cannot seem to find a solution that works for a button. I thought that tracking tap position would be a fundamental system function available all the time.

This makes sense cause a large majority of the time, it doesn’t matter where the button is, but only that it was tapped.

You are going to have to make a custom button most likely, meaning make a shape and add a tap gesture

I believe you are right. Thanks again for the second opinion!

1 Like

Best of luck! You can do it!