MacOS SwiftUI 打开侧边栏的奇怪行为

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

从图像中可以看出,打开侧面菜单时似乎出现了奇怪的行为。

你能告诉我如何解决这个问题吗?

enter image description here

内容视图

import SwiftUI

struct ContentView: View {
    var body: some View {
        VStack {
            Text("Hello, world!")
        }.navigationTitle("Explore")
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

项目SchemaApp

import SwiftUI

@main
struct projectSchemaApp: App {
    var body: some Scene {
        WindowGroup {
            SidebarView()
                .frame(minWidth: 600, minHeight: 600)
        }
    }
}

侧边栏视图

import SwiftUI

struct SidebarView: View {
    var body: some View {
        NavigationView {
            List {
                Text("Simboli SF")
                Group{
                    NavigationLink(destination: ContentView()) {
                        Label("Tutti", systemImage: "message")
                    }
                    NavigationLink(destination: ContentView()) {
                        Label("Novità", systemImage: "cloud.sun")
                    }
                    NavigationLink(destination: ContentView()) {
                        Label("Multicolore", systemImage: "bolt.car")
                    }
                    NavigationLink(destination: ContentView()) {
                        Label("Comunicazione", systemImage: "pills")
                    }
                    NavigationLink(destination: ContentView()) {
                        Label("Meteo", systemImage: "ticket")
                    }
                    NavigationLink(destination: ContentView()) {
                        Label("Oggetti e strumenti", systemImage: "function")
                    }
                }
                Spacer()
                Text("Libreria")
                NavigationLink(destination: ContentView()) {
                    Label("Simboli personalizzati", systemImage: "option")
                }
            }
            .listStyle(SidebarListStyle())
            .navigationTitle("Explore")
            .frame(minWidth: 10, maxWidth: 200)
            .toolbar{
                ToolbarItem(placement: .primaryAction){
                    Button(action: toggleSidebar, label: {
                        Image(systemName: "sidebar.left")
                    })
                }
            }
            ContentView()
        }
    }
}

func toggleSidebar() {
        NSApp.keyWindow?.firstResponder?.tryToPerform(#selector(NSSplitViewController.toggleSidebar(_:)), with: nil)
}

struct SidebarView_Previews: PreviewProvider {
    static var previews: some View {
        SidebarView()
    }
}
swift xcode macos swiftui sidebar
1个回答
0
投票

删除 minHeight 和 minWidth 后问题是否仍然存在?

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