1

我从 Xcode 12 beta 6 (12A8189n) 应用程序模板创建了一个 SwiftUI“多平台”(iOS 和 macOS)应用程序。

我的问题是我的一个观点 ,AnotherView显示不正确。这是一个显示问题的 gif。请注意,AnotherView带有导航堆栈的显示已经推送到不存在的视图。点击后退按钮会显示预期的屏幕,但它仅显示部分填充预期区域。

演示

这是代码:

TestNavigationApp.swift

import SwiftUI

@main
struct TestNavigationApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

内容视图.swift

import SwiftUI

struct ContentView: View {
    
    @State private var presentingFirstView = false
    
    var body: some View {
        Button(action: { self.presentingFirstView = true }) {
            
            Text("Present First View")
        }
        .sheet(isPresented: $presentingFirstView) {

            FirstView(isPresented: $presentingFirstView)
        }
    }
}

FirstView.swift

import SwiftUI

struct FirstView: View {
    
    @Binding var isPresented: Bool

    var body: some View {
        
        NavigationView {
            EmbeddedView()
                .navigationBarTitle("First View", displayMode: .large)
        }
    }
}

EmbeddedView.swift

import SwiftUI

struct EmbeddedView: View {
    
    @State private var presentingAnotherView = false
    
    var body: some View {

        VStack {
            Text("Embedded View")
            
            Button(action: { self.presentingAnotherView = true }) {
                
                Text("Present Another View")
            }
        }
        .sheet(isPresented: $presentingAnotherView) {

            AnotherView(isPresented: $presentingAnotherView)
        }
    }
}

另一个视图.swift

import SwiftUI

struct AnotherView: View {
    
    @Binding var isPresented: Bool
    
    var body: some View {
        NavigationView {
            Text("Another View")
                .navigationBarTitle("Another View", displayMode: .large)
        }
    }
}

无论如何,不​​确定这里发生了什么。任何建议表示赞赏。

4

1 回答 1

1

尝试明确使用导航视图样式

var body: some View {
    NavigationView {
        Text("Another View")
            .navigationBarTitle("Another View", displayMode: .large)
    }.navigationViewStyle(StackNavigationViewStyle())
}
于 2020-08-31T03:39:17.063 回答