Reputation: 47
This is a simplified representation of my code. How do I add an animation to Text("hi")
here? It's a really simple appearance animation.
import SwiftUI
struct Test: View {
@State var showText:Bool = true
var body: some View {
List{
HStack{
Image(systemName: "square")
Text("tap")
}
.onTapGesture {
showText.toggle()
}
if (showText) {
Text("Hi")
}
}
}
}
struct Test_Previews: PreviewProvider {
static var previews: some View {
Test()
}
}
Upvotes: 3
Views: 121
Reputation: 54466
You can use withAnimation
block:
.onTapGesture {
withAnimation {
showText.toggle()
}
}
You can also change the default animation type, duration etc:
withAnimation(.easeInOut(duration: 0.4)) { ... }
Upvotes: 2