0

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:)

  • Welcome to Stack Overflow! Please take the [tour](https://stackoverflow.com/tour) and see: [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask) and [How to create a Minimal, Reproducible Example (MRE)](https://stackoverflow.com/help/minimal-reproducible-example). – Yrb Feb 28 '22 at 17:47

2 Answers2

1

On macOS it is the standard behavior in NavigationView to show the views (parent view and destination view) next to each other: https://developer.apple.com/design/human-interface-guidelines/macos/windows-and-views/column-views/

If you don't want that you can do:

    NavigationView {
        ...
    }
    .navigationViewStyle(.stack)
ChrisR
  • 9,523
  • 1
  • 8
  • 26
0

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