我使用 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
""")
}
}
}
}
您可以将 .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)
}