最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

scrollview - Why does LazyVStack footer stutter when section height exceeds screen frame in SwiftUI? - Stack Overflow

programmeradmin2浏览0评论

I am having some issues with sticky footers on PinnedScrollableViews in SwiftUI for iOS. I am working on a LazyVStack embedded in a ScrollView with footers on each section of the LazyVStack. The size of each section is dynamic and may change dependent on how many line items a user adds to the section. I noticed that when more line items are added to the section and thus, the height of the section exceeds the frame of the screen at a certain point, the footer stutters for a short moment. It roughly seems to be moment when the bottom of the corresponding section is reached - but I am not too sure

I tried the following code (simplified for illustration). I got the foundation from /swiftui/pinnedScrollableViews/ and only adjusted it a little:

  • took footers instead of headers
  • adjusted the height of the rectangle to exceed frame of a screen
  • added a preceding section without a footer to have it directly displayed when opening the view
struct StickyHeaderViewExample: View {

    var stickyHeaderView: some View {
        RoundedRectangle(cornerRadius: 25.0, style: .continuous)
            .fill(Color.gray)
            .frame(maxWidth: .infinity)
            .frame(height: 64)
            .overlay(
                Text("Section")
                    .foregroundColor(Color.white)
                    .font(.largeTitle)
            )
    }
    var body: some View {
        NavigationView {
            ScrollView {
                LazyVStack(alignment: .center, spacing: 40, pinnedViews: [.sectionFooters], content: {
                    Section {
                        Text("Section 1")
                            .foregroundColor(.blue)
                            .font(.headline)
                            .padding()
                    }
                    ForEach(0...5, id: \.self) { count in
                        Section(footer: stickyHeaderView) {
                            MyCell()
                        }
                    }
                })
            }
        }      

    }
}
struct MyCell: View {
    var body: some View {
        VStack {
            Rectangle()
                .fill(Color.red)
                .frame(width: 100, height: 750)
            HStack {
                Image(systemName: "heart")
                Text("WWDC 20")
                    .foregroundColor(.blue)
                    .font(.headline)
            }
            Text("PinnedScrollableViews")
                .foregroundColor(.blue)
                .font(.subheadline)
        }
    }
}

Now, what I receive is the following. As you can see, it stutters/disappears for a short moment/at a certain position when scrolling down.

enter image description here

enter image description here

Do you know how I can fix this? Has anyone maybe faced the same or similar issues with footers in PinnedScrollableViews? I would really appreciate any help

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论