本文介绍了非模态呈现视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的应用创建登录页面,并希望以用户无法返回的方式显示主屏幕.在 Swift UI 中,我如何呈现它以便新视图不会以类似卡片的样式呈现?我知道这种呈现风格现在是 iOS 13 的默认样式.

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.

这是我已经拥有的.

import SwiftUI

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

我想要全屏显示.

推荐答案

使用 NavigationViewNavigationButton 并隐藏目标视图的导航栏的后退按钮.

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

例如:

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

            }
        }
    }
}

您还可以通过执行 let destinationView = Text("Destination").navigationBarHidden(true) 来完全禁用目标视图的导航栏.

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

这篇关于非模态呈现视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 02:50