Present a View Non-Modally

2019-08-26 07:24发布

问题:

I am creating a sign in page for my app and would like to present the home screen in a way that the user can not go back. In Swift UI how do I present it so the new view does not present in a card like style? I know this presenting style is now default for iOS 13.

This is what I already have.

import SwiftUI

struct Test : View {
    var body: some View {
        PresentationButton(Text("Click to show"), destination:   Extra()  )
    }
}

I would like the view to present full screen.

回答1:

Use a NavigationView with a NavigationButton and hide the destination view's navigation bar's back button.

For example:

struct ContentView : View {
    let destinationView = Text("Destination")
        .navigationBarItem(title: Text("Destination View"), titleDisplayMode: .automatic, hidesBackButton: true)

    var body: some View {
        NavigationView {
            NavigationButton(destination: destinationView) {
                Text("Tap Here")

            }
        }
    }
}

You can also disable the destination view's navigation bar altogether by doing let destinationView = Text("Destination").navigationBarHidden(true).



标签: swiftui