我在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()
}
}