2

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:

enter image description here

macOS:

enter image description here

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)
        
    }
}
ios coder
  • 1
  • 4
  • 31
  • 91
  • @Asperi: That is clear, no issue there. But also did not helped in that case. For example I tried to use the updated code! It did not help either! :( The issue is not easy that it looks like. – ios coder Feb 14 '22 at 16:01
  • 1
    This topic might be helpful https://stackoverflow.com/questions/59385446/change-window-size-based-on-navigationview-in-a-swiftui-macos-app. – Asperi Feb 14 '22 at 16:29
  • Yes, the issue is more or less same, I must see if there is any SwiftUI-isch approach in that link. – ios coder Feb 14 '22 at 17:18

0 Answers0