In SwiftUI, I've managed to make a Button animate right when the view is first drawn to the screen, using the animation(_:)
modifier, that was deprecated in macOS 12.
I've tried to replace this with the new animation(_:value:)
modifier, but this time nothing happens:
So this is not working:
struct ContentView: View {
@State var isOn = false
var body: some View {
Button("Press me") {
isOn.toggle()
}
.animation(.easeIn, value: isOn)
.frame(width: 300, height: 400)
}
}
But then this is working. Why?
struct ContentView: View {
var body: some View {
Button("Press me") {
}
.animation(.easeIn)
.frame(width: 300, height: 400)
}
}
The second example animates the button just as the view displays, while the first one does nothing
showChat
when the view appears? Explicit animations watch for a change in the value that is included in the init. – BelorussiashowChat
, the whole view is dismissed – Roguery