gpt4 book ai didi

SwiftUI 和 Mac 催化剂 : Sidebar is not displayed correctly

转载 作者:行者123 更新时间:2023-12-04 13:54:07 32 4
gpt4 key购买 nike

我启用了 Mac Catalyst对于 iPad App并遇到了一个奇怪的Display ProblemSidebar .
Screenshot of the Mac Catalyst App
代码:

@State private var selection: NavigationItem? = .start

NavigationView {
List(selection: $selection) {
NavigationLink(destination: StartView(), tag: NavigationItem.start, selection: $selection) {
Label("Start", systemImage: "square.grid.2x2.fill")
.accessibility(label: Text("Start"))
}
.tag(NavigationItem.start)

// 4 more Items
}
.listStyle(SidebarListStyle())
.navigationBarTitle("Impfpass+")

StartView()
}
问题:此代码生成 Standard SidebariPad但是,正如您所见, Mac Version这个看起来很奇怪 angular design .我怎样才能实现 Standard macOS Sidebar Design ?

最佳答案

我遇到了同样的问题。
原来内置的 SidebarListStyle 在 macOS 上表现不正确。
Here是 Steven Troughton-Smith 建议的解决方案,它意味着将 SwiftUI View 包装在 UISplitViewController 中。
基本上 :

struct SidebarSplitView: View, UIViewControllerRepresentable {
typealias UIViewControllerType = UISplitViewController
let splitViewController = UISplitViewController(style: .doubleColumn)

var columnA = UIViewController()
var columnB = UIViewController()

init<A:View, B:View>(@ViewBuilder content: @escaping () -> TupleView <(A,B)>) {
let content = content()
columnA = UIHostingController(rootView: content.value.0)
columnB = UIHostingController(rootView: content.value.1)
columnA.view.backgroundColor = .clear
columnB.view.backgroundColor = .clear
splitViewController.viewControllers = [columnA, columnB]
}

func makeUIViewController(context: Context) -> UIViewControllerType {
splitViewController.primaryBackgroundStyle = .sidebar
return splitViewController
}

func updateUIViewController(_ uiView: UIViewControllerType, context: Context) { }
}
然后你就可以称之为:
struct ContentView: View {
var body: some View {
SidebarSplitView {
Sidebar() // here goes your sidebar
MainView() // here your main view
}
}
}

关于SwiftUI 和 Mac 催化剂 : Sidebar is not displayed correctly,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65749388/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com