偏移时会裁剪SwiftUI列表/表单/ ScrollView

时间:2020-05-08 15:15:21

标签: swift swiftui-list swiftui swiftui-form

我更改了列表的y偏移,现在正在对其进行裁剪。
我正在尝试这样做,以便在滚动时可以部分看到标题下方的文本和视图顶部的按钮。换句话说,我希望屏幕的顶部稍微透明。

我将偏移量添加到列表中,以使其与顶部的信息不重叠。

list image

上面的图像显示了我的代码中的VStack。我以为VStack可能会妨碍您,所以我将其注释掉,结果如下图所示:

list without VStack at top

这是我的代码:

var body: some View {
    ZStack {

        VStack {
            HStack {

                Button(action: {self.showAccountView.toggle()}) {
                    Image(systemName: "person.fill")
                        .renderingMode(.original)
                        .font(.system(size: 20, weight: .bold))
                        .frame(width: 44, height: 44)
                        .modifier(NavButtons())
                }
                .sheet(isPresented: $showAccountView) {
                    AccountView()
                }
                Spacer()
                Button(action: { self.showHelpCenter.toggle()}) {
                    Image(systemName: "questionmark")
                        .renderingMode(.original)
                        .font(.system(size: 20, weight: .bold))
                        .modifier(NavButtons())
                }
                .sheet(isPresented: $showHelpCenter) {
                    HelpCenter()
                }
            }
            .frame(maxWidth: .infinity)
            .padding(.horizontal)
            Spacer()
        }
        List {
            ForEach (store.allLogs) { thing in
                VStack (alignment: .leading) {
                    HStack {
                        Text("\(thing.date) , \(thing.time)")
                    }
                    Text(thing.notes)
                        .multilineTextAlignment(.leading)
                }
            }
        }.offset(y: 50)

    }
}

编辑:

这是一种可能的解决方案:

struct MyList: UIViewRepresentable {
    func makeUIView(context: Context) -> UITableView {
        let view = UITableView()
        view.clipsToBounds = false

        return view
    }

    func updateUIView(_ uiView: UITableView, context: Context) {

    }
}

,然后您将使用makeUIView和updateUIView来更新单元格。这只是一团糟,并且那时还没有真正使用SwiftUI。

第二次修改
我发现了scrollView和表单存在此问题:
ScrollView, Form, and List all being clipped when offset
黑色是背景。这是这三个代码:

Group {
        List ((0 ... 10), id: \.self) {
            Text("Row \($0)")
        }
        .offset(y: 200)
        .border(Color.blue, width: 3)
        .background(Color.black)

        ScrollView {
            Text("Text")
        }
        .foregroundColor(.white)
        .offset(y: 200)
        .border(Color.blue, width: 3)
        .background(Color.black)

        Form {
            Text("Text")
        }
        .offset(y: 200)
        .border(Color.blue, width: 3)
        .background(Color.black)
    }

以下是列表的线框:
Wireframes of list

以下是与“列表/表单/滚动视图”高度相同的框架的名称:

列表:
PlainList.BodyContent
ListCore.Container
ListRepresentable
查看主机
表格包装器
UpdateCoalescingTableView

表格:
GroupList.BodyContent
ListCore.Container
ListRepresentable
查看主机
表格包装器
UpdateCoalescingTableView

ScrollView:
ScrollViewBody
SystemScrollView
查看主机
HostingScrollView

我想我的问题已经从“我该怎么做...”变为“为什么会发生?” 我对到底发生了什么感到很困惑。

0 个答案:

没有答案