LazyVGrid 内的 NavigationLink 在 swiftUI macOS 中无法正确显示

Sal*_*zzo 1 macos swiftui swiftui-list swiftui-navigationlink swiftui-scrollview

我正在 SwifUI 中开发一个跨平台应用程序。在 iPhone / iPad 上,这段代码在 MacOS 上运行得非常好,相反,当我插入 NavigationLink 时,ForecastCardView 被完全切断。当我删除 NavigationLink 时,一切都会正确呈现。

带有导航链接

var FullSection: some View {
    LazyVGrid(columns: homeConfigurationUI.columns, alignment: .center, spacing: 20) {
            NavigationLink(destination: Text("test")) {
                  ForecastCardView(viewModel:  ForecastCardViewModel.initForTest())
            }.frame(width: 300, height: 300, alignment: .center)
        }
        .border(Color.yellow)
        .frame(minWidth: 300, idealWidth: 400, maxWidth: 600, minHeight: 0, idealHeight: 500, maxHeight: .infinity, alignment: .center)
}
Run Code Online (Sandbox Code Playgroud)

带有导航链接的图像

没有导航链接

var FullSection: some View {
        LazyVGrid(columns: homeConfigurationUI.columns, alignment: .center, spacing: 20) {
                ForecastCardView(viewModel:  ForecastCardViewModel.initForTest())
            }
            .border(Color.yellow)
            .frame(minWidth: 300, idealWidth: 400, maxWidth: 600, minHeight: 0, idealHeight: 500, maxHeight: .infinity, alignment: .center)
    }
Run Code Online (Sandbox Code Playgroud)

没有导航链接的图像

一切都在 ScrollView 内,我尝试插入一个 List 一个 VStack,但没有结果。我尝试在每个组件上放置一个静态框架,但无济于事。

clu*_*der 7

您必须设置buttonStylePlainButtonStyle()

\n
var FullSection: some View {\n    LazyVGrid(columns: homeConfigurationUI.columns, alignment: .center, spacing: 20) {\n            NavigationLink(destination: Text("test")) {\n                  ForecastCardView(viewModel:  ForecastCardViewModel.initForTest())\n            }\n               .buttonStyle(PlainButtonStyle()) // <\xe2\x80\x94 HERE\n               .frame(width: 300, height: 300, alignment: .center)\n        }\n        .border(Color.yellow)\n        .frame(minWidth: 300, idealWidth: 400, maxWidth: 600, minHeight: 0, idealHeight: 500, maxHeight: .infinity, alignment: .center)\n}\n
Run Code Online (Sandbox Code Playgroud)\n