簡體   English   中英

SwiftUI:在特定屏幕上隱藏導航欄

[英]SwiftUI: Hide Navigation Bar on Specific Screens

似乎我無法選擇要在 swift UI 中隱藏導航欄的頁面。

我有以下屏幕:

主要的

struct Main: View {
    var body: some View {
        NavigationView {
                Home()
            }
        }
}

struct Home: View {
    var body: some View {
            NavigationLink(destination: Details()) {
                    Text("Go Next")
            }
        // I expect the navigation bar to show up here, and it does
        .navigationBarTitle("Home")
        .navigationBarHidden(false)
    }
}

細節

struct Details: View {
    @Environment(\.presentationMode) var mode: Binding<PresentationMode>

    var body: some View {
            Button(action: { self.mode.wrappedValue.dismiss() }) {
                Text("Go Back")
            }
        // I expect the navigation bar to be hidden here
        // At first, it is hidden. Then, after a second, it pops up 
        // with the title "Details"
        .navigationBarTitle("Details")
        .navigationBarHidden(true)
    }
}

要么我做錯了(可能),要么 Apple 有一些工作要做(也可能)。

正如我之前看到的,當您同時使用兩者時,會出現問題:

.navigationBarTitle("some text")
.navigationBarHidden(true)

在下面的代碼中,沒有導航欄工作人員,也沒有彈出任何內容:

struct Details: View {
    @Environment(\.presentationMode) var mode: Binding<PresentationMode>

    var body: some View {
            Button(action: { self.mode.wrappedValue.dismiss() }) {
                Text("Go Back")
            }
        .navigationBarHidden(true)
        .navigationBarBackButtonHidden(true) // even no back button
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM