Search code examples
xcodemacosswiftuiswiftui-navigationlinkswiftui-navigationview

view display on the right of the window


hello i have an issue with my project on Xcode when I use navigation view, the window display not normally and appear on the right of the window already displayed,

here is the code.

NavigationLink(destination: Acceuil())
                        {
                            HStack{
                               Image("icone_connexion")
                                    .font(.system(size: 15))
                                 //   .scaledToFill()


                                Text("se connecter")
                                        .font(.system(size: 30))
                          
                            }.cornerRadius(60)
                           .frame(width: 400, height: 60)
                            
                        } .background(Capsule().fill(Color(red: 55/255, green: 66/255, blue: 114/255, opacity:1)))
                        .frame(width: 400, height: 60) //fin navigationlink
                        .buttonStyle(PlainButtonStyle())

I would like that the new window replace the older one:)


Solution

  • so I found this code

     import SwiftUI
    
        struct ContentView: View {
            @State private var show = false
            var body: some View {
                VStack{
                    if !show {
                        RootView(show: $show)
                            .frame(maxWidth: .infinity, maxHeight: .infinity)
                            .background(Color.blue)
                            .transition(AnyTransition.move(edge: .leading)).animation(.default)
                    }
                    if show {
                        NextView(show: $show)
                            .frame(maxWidth: .infinity, maxHeight: .infinity)
                            .background(Color.green)
                            .transition(AnyTransition.move(edge: .trailing)).animation(.default)
                    }
                }
            }
        }
    
        struct RootView: View {
            @Binding var show: Bool
            var body: some View {
                VStack{
                    Button("Next") { self.show = true }
                    Text("This is the first view")
                }
            }
        }
    

    it work grate for me so thanks you for your help