NavigationSplitView 侧边栏以横向方式显示 iPad 中的详细信息。有没有办法避免这种情况?

问题描述 投票:0回答:1

我使用 NavigationSplitView 因为它有漂亮的侧边栏、工具栏、详细布局。

在肖像中效果很好。然而,在横向中,存在这种不良的副作用,即当我希望侧边栏看起来更像侧边栏覆盖内容时,侧边栏会推送内容。

有办法避免这种情况吗? 我尝试过 Z 堆栈,但无法使背景透明。

detail
上的叠加效果很好,但我无法避免内容翻译一点。

struct ContentView: View {
    var body: some View {
        ZStack {
            NavigationSplitView {
                List {
                    Text("Sidebar")
                        .listStyle(SidebarListStyle())
                }
                .background{
                    Color.gray.ignoresSafeArea()
                }
            } detail: {
                Text("""
            Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when 
            """)
            }
        }
    }
}

Sidebar pushes content

ios swiftui
1个回答
0
投票

您可以将 .navigationSplitViewStyle() 修饰符与 .prominentDetail 样式一起使用。

var body: some View {
            NavigationSplitView() {
                List {
                    Text("Sidebar")
                        .listStyle(SidebarListStyle())
                }
                .background{
                    Color.gray.ignoresSafeArea()
                }
            } detail: {
                Text("""
            Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when
            """)
            }
        .navigationSplitViewStyle(.prominentDetail)
    }

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.