簡體   English   中英

SwiftUI 列表中神秘的前導/尾隨填充?

[英]SwiftUI mysterious leading/trailing padding in List?

在我的 SwiftUI 列表視圖中有可滾動的帖子,它們有一個神秘的前導和尾隨填充,我無法弄清楚它來自哪里? (見藍色圈出的圖片)

我希望帖子圖像一直延伸到手機屏幕的邊緣,所以根本沒有空白。

我在我的 PostCell 上放置了紅色的背景顏色,正如您在圖像中看到的那樣,填充似乎不是來自 PostCell,因為您在它的任一側看到了前導/尾隨的白色填充。

下面是我的應用程序中的完整視圖層次結構,層次結構中的任何位置都沒有填充,這似乎是大約 30 點。

我假設默認情況下在某處應用此填充?

關於如何擺脫這種填充的任何想法?

在此處輸入圖像描述

根視圖

struct RootView: View {
    var body: some View {
        TabView {
            // OTHER VIEW
            // OTHER VIEW
            // OTHER VIEW
            // OTHER VIEW
            ProfileView(profileVM: ProfileViewModel())
        }
    }
}

父視圖

struct ProfileView: View {
    @StateObject var profileVM: ProfileViewModel
    @State private var presentSettings: Bool = false

    var body: some View {
        NavigationView {
                List {
                    ProfileContent(profileVM: profileVM)
                }
                .clipped()
                .listStyle(PlainListStyle())
                .refreshable {
                    Task.detached { await profileVM.loadData() }
                }
                .navigationViewStyle(StackNavigationViewStyle())
                .navigationBarTitle(Text(""), displayMode: .inline)
                .background (
                    NavigationLink("", destination: ListView(profileVM: profileVM), isActive: $profileVM.presentPostView).isDetailLink(false)
                )
        }
    }
}

兒童視角

struct ListView: View {
    @Environment(\.presentationMode) var presentation
    @ObservedObject var profileVM: ProfileViewModel
        
    var body: some View {
        ScrollViewReader { proxy in
            List(profileVM.usersPosts, id: \.id) { post in
                PostCell(post: post)
                    .background(Color.red)
            }
            .clipped()
            .listStyle(PlainListStyle()) 
            .navigationViewStyle(StackNavigationViewStyle())
            .navigationBarTitle(Text("your posts"), displayMode: .inline)
            .navigationBarBackButtonHidden(true)
            .toolbar(content: {
                ToolbarItem(placement: .navigationBarLeading) {
                    ZStack {
                        Button(action: {print("action")}, label: {Text("Press")})
                    }.padding(.leading, 10)
                }
            })
        } 
    }
}

我假設您需要將行插圖歸零

PostCell(post: post)
    .background(Color.red)
    .listRowInsets(EdgeInsets())   // << here !!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM