skip to Main Content

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

2

Answers


  1. Chosen as BEST ANSWER

    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


  2. 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)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search