How to present a view full-screen in SwiftUI?

前端 未结 4 2076
长情又很酷
长情又很酷 2021-01-02 05:33

I worked to a login view, now I want to present the view after login, but I do not want the user to have the possibility to return to the login

4条回答
  •  情深已故
    2021-01-02 06:24

    I made this extension for myself. Any feedback/ideas are welcome. :)

    https://github.com/klemenkosir/SwiftUI-FullModal

    Usage

    struct ContentView: View {
    
        @State var isPresented: Bool = false
    
        var body: some View {
            NavigationView {
                Button(action: {
                    self.isPresented.toggle()
                }) {
                    Text("Present")
                }
                .navigationBarTitle("Some title")
            }
            .present($isPresented, view: ModalView(isPresented: $isPresented))
        }
    }
    
    struct ModalView: View {
    
        @Binding var isPresented: Bool
    
        var body: some View {
            Button(action: {
                self.isPresented.toggle()
            }) {
                Text("Dismiss")
            }
        }
    }
    

提交回复
热议问题