Hello, I am trying to implement an action on tap gesture on a Text which is moving with animation using SwiftUI.
When the Text is moving, the tap gesture seems to register only when I tap at the final destination of the Text, and not when I tap on the moving Text
struct ContentView: View {
@State var offsetY : CGFloat = 0
var body: some View {
VStack {
Text("Animate")
.onTapGesture {
withAnimation(.linear(duration: 15)){
offsetY = 200
}
}
Text("Hello, world!")
.offset(y: offsetY)
.onTapGesture {
print("Tap")
}
}
}
}
Is there a way to make tapGesture register when I tap on the moving Text ?
By the way, it works when I encapsulate the Text in a NavigationLink, but I don't want to have a NavigationLink in my case.
struct ContentView: View {
@State var offsetY : CGFloat = 0
var body: some View {
VStack {
Text("Animate")
.onTapGesture {
withAnimation(.linear(duration: 15)){
offsetY = 100
}
}
NavigationLink(destination: EmptyView()) {
Text("Hello, world!")
}.offset(y: offsetY)
.onTapGesture {
print("Tap")
}
}
}
}