【问题标题】:SwiftUI NavigationView on MacOS leaves padding above ListMacOS 上的 SwiftUI NavigationView 在 List 上方留下填充
【发布时间】:2020-11-11 23:11:28
【问题描述】:

我有一个 NavigationView,它在 NavigationLink 列表上方留下了看起来像填充的东西,我不知道如何摆脱它?

这是调用 NavigationView 的视图:

struct SearchView: View {
    @EnvironmentObject var networkManager:NetworkManager
    
    var body: some View {
        VStack {
            SearchBar()//<- This view houses the content above the list but contains no padding after the divider and when the filesToDisplay is false it shrinks to the divider as expected
            if networkManager.filesToDisplay {
                ResultsView()
            }
        }
    }
}

这是导航视图:

struct ResultsView: View {
    @EnvironmentObject var networkManager:NetworkManager
    var body: some View {
        NavigationView {
            List {
                ForEach(networkManager.FileList!.items) { file in
                    NavigationLink(destination: FileDetail(fileDetail: file)) {
                        FileRow(fileRow: file)
                    }
                }
            }
            Rectangle().frame(maxWidth: 0, maxHeight: .infinity)
            }.frame(minHeight:500, idealHeight: 550, maxHeight: .infinity)
    }
}

我认为问题可能与 navigationBarTitle 有关,但 MacOS 似乎没有使用它?我尝试了各种不同的填充和 listRowInsets,但没有任何效果。

【问题讨论】:

    标签: macos swiftui swiftui-list swiftui-navigationlink


    【解决方案1】:

    添加显式间距

    VStack(spacing: 0) {   // << here !!
        SearchBar()
        if networkManager.filesToDisplay {
            ResultsView()
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2021-01-04
      • 1970-01-01
      • 2020-08-29
      • 1970-01-01
      • 2021-02-08
      • 1970-01-01
      • 2020-09-21
      相关资源
      最近更新 更多