SwiftUI macOS 右侧边栏检查器

Tay*_*lor 11 macos swiftui macos-big-sur

我有一个基于文档的 SwiftUI 应用程序。我想制作一个类似于 Xcode 中的检查器侧边栏。

从 Xcode 的 Document App 模板开始,我尝试了以下操作:

struct ContentView: View {
    @Binding var document: DocumentTestDocument
    @State var showInspector = true

    var body: some View {
        HSplitView {
            TextEditor(text: $document.text)
            if showInspector {
                Text("Inspector")
                    .frame(maxWidth: .infinity, maxHeight: .infinity)
            }
        }
        .toolbar {
            Button(action: { showInspector.toggle() }) {
                Label("Toggle Inspector", systemImage: "sidebar.right")
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这产生了:

截屏

如何像在 Xcode 中一样将右侧边栏扩展到全高?

NavigationView 适用于左侧边栏,但我不确定如何为右侧边栏执行此操作。

Rib*_*ena 2

SwiftUI 仍处于测试阶段,但很快就会在 iOS 17、tvOS17 和 macOS14 中推出,将提供这种类型的检查器:

ContentView()
    .inspector($showInspector) {
        InspectorView()
    }
Run Code Online (Sandbox Code Playgroud)

以下是 WWDC23 的视频:https://developer.apple.com/videos/play/wwdc2023/10161

以及文档的链接:https://developer.apple.com/documentation/corelocationui/locationbutton/4200336-inspector/