1

I'm playing around a bit with SwiftUI and want to build a test app but I don't like the Modal presentation style, I rather have them full screen. After some googling I got this:

var body: some View {
        Group {
            if one {
                MainView()
            } else if two {
                SecondView()
            } else if three {
                ThirdView()
            } else {
                ForthView()
            }
        }
    }

How this works is that e.g. inside the ContentView() you click a button which will toggle a boolean @State, which itself will reload this view and one of the views inside of the Group will show. Now I want this to have an animation/transition so you actually see MainView() slide in from the right, and SecondView() transition to top.

I've tried putting each view inside a withAnimation { } and also setting .transition(move(.top)) but nothing seems to work.

Is this possible to do in SwiftUI?

I want these to animate

maniponken
  • 265
  • 3
  • 15
  • 1
    The following solutions should be helpful [Transitions not working with a router in SwiftUI](https://stackoverflow.com/a/61981563/12299030), [How do I add Animations to Transitons between custom NavigationItems made from AnyView?](https://stackoverflow.com/a/59087574/12299030). Actually described scenario already solved, so just search for more. – Asperi Jun 17 '20 at 13:43
  • set the `.transition()` up to each view and embrace code to change the state with `withAnimation`. – Kyokook Hwang Jun 18 '20 at 01:47

0 Answers0