如何使用SwiftUI ScrollView滚动到ScrollView框架之外,以允许滚动内容显示在页眉/脚视图下?

时间:2020-05-19 17:48:04

标签: swiftui

我在ZStack上有一个页眉和一个脚,中间有一个带有内容的ScrollView。这样可以使指示器在中间部分可见,但是这也意味着ScrollView内的内容不会扩展到页眉和页脚,在许多具有模糊效果的应用程序中都可以看到。当前有什么方法可以使ScrollView将其内容扩展到其框架之外?

import SwiftUI




struct ContentView: View {

    var fullyUnder: some View {
        ZStack {
            ScrollView(.vertical, showsIndicators: true) {
                VStack {
                    ForEach(0..<50) { _ in
                        Rectangle().foregroundColor(Color.red).frame(width: 50, height: 50)
                    }
                }
            }

            VStack {
                Color.green.opacity(0.50).frame(height: 30)
                Spacer()
                Color.blue.opacity(0.50).frame(height: 30)
            }


        }
    }

    var fullyIn: some View {
        VStack {
            Color.green.opacity(0.50).frame(height: 30)

            ScrollView(.vertical, showsIndicators: true) {
                VStack {
                    ForEach(0..<50) { _ in
                        Rectangle().foregroundColor(Color.red).frame(width: 50, height: 50)
                    }
                }
            }

            Color.blue.opacity(0.50).frame(height: 30)

        }
    }


    var body: some View {
        VStack {

            // This shows the content under the header/footer but the indicator also goes under
            fullyUnder

            Divider()

            // This shows the indicator properly, but the content doesn't go udner the header/footer
            fullyIn

        }
    }


}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

0 个答案:

没有答案