I want remove a green view with no animation but displace a blue view when the green view gone with animation.
The code is like this in below, this works well in iOS, but not in macOS, because in macOS the window size change with no respect to happening animation, how could I refactor my codes that window size change size responsible to animation, that I could be able to see the entire animation.
struct ContentView: View {
@State private var isPresented: Bool = true
var body: some View {
if (isPresented) {
Color.green.frame(height: 400.0)
}
Color.blue.frame(height: 100.0).onTapGesture {
isPresented.toggle()
}
.animation(Animation.linear(duration: 3.0), value: isPresented)
}
}
ios:
macOS:
updated part for macOS:
struct ContentView: View {
@State private var isPresented: Bool = true
var body: some View {
VStack {
Color.green.frame(height: isPresented ? 400.0 : 0.0)
Color.blue.frame(height: 100.0).onTapGesture {
isPresented.toggle()
}
}
.animation(Animation.linear(duration: 3.0), value: isPresented)
}
}