struct TapGestureLocationExample: View { @State private var pos = CGPoint(x: 100, y: 100) var body: some View { VStack { Circle() .fill(Color.orange.gradient) .frame(width: 50) .position(pos) Spacer() } .background(Color.gray.opacity(0.3)) .onTapGesture { location in withAnimation(Animation.easeOut(duration: 2)) { pos = location } } } }
.onTapGesture(coordinateSpace: .global)
struct TapGestureLocationExample: View { @State private var pos = CGPoint(x: 100, y: 100) var body: some View { Circle() .fill(Color.orange.gradient) .frame(width: 50) .position(pos) .onTapGesture(coordinateSpace: .global) { location in withAnimation(Animation.easeOut(duration: 2)) { pos = location } } } }
With that we have reached the end of this article. Thank you once again for reading. Also subscribe our newsletter at https://www.devtechie.com