使用TabView作为页面查看器使用.tabViewStyle(PageTabViewStyle())很好,但是尝试通过应用edgesIgnoringSafeArea让它从边缘运行似乎不起作用。
我在这里错过了什么?
struct ContentView: View {
    let colors: [Color] = [.red, .green, .blue]
    var body: some View {
        TabView {
            ForEach(0...2, id: \.self) { index in
                Rectangle()
                    .fill(colors[index])
            }
        }
        .tabViewStyle(PageTabViewStyle())
        .edgesIgnoringSafeArea(.all)
    }
}

将另一个.edgesIgnoringSafeArea(.all)添加到Rectangle或ForEach中也不起作用。
请注意,所有这些问题都是不同的,因为它们不使用使用PageTabViewStyle()
在这种情况下,他们的解决方案(添加edgesIgnoringSafeArea(.all))不起作用。
发布于 2020-12-03 14:23:27
struct ContentView: View {
    let colors: [Color] = [.red, .green, .blue]
    var body: some View {
        ScrollView {
            TabView {
                ForEach(0...2, id: \.self) { index in
                    Rectangle()
                        .fill(colors[index])
                }
            }
            .frame(
                width: UIScreen.main.bounds.width ,
                height: UIScreen.main.bounds.height
            )
            .tabViewStyle(PageTabViewStyle())
            
        }
        .edgesIgnoringSafeArea(.all)
    }
}发布于 2021-10-17 09:09:36
SwiftUI 3.0中的更新:
 TabView {
            ForEach(0...2, id: \.self) { index in
                Rectangle()
                    .fill(colors[index])
            }
            .ignoresSafeArea()
        }
        .tabViewStyle(PageTabViewStyle())
        .edgesIgnoringSafeArea(.all)发布于 2020-06-26 13:55:07
这是我得到的最大限度..。无论如何,我认为它最初是一个bug,值得向苹果提交反馈。
用Xcode 12b测试

struct TestPagingStyle: View {
    let colors: [Color] = [.red, .green, .blue]
    var body: some View {
        ZStack {
            Color.black.overlay(
                GeometryReader { gp in
                    TabView {
                        ForEach(0..<3, id: \.self) { index in
                            Text("Hello, World \(index)")
                                .frame(width: gp.size.width, height: gp.size.height)
                                .background(colors[index])
                        }
                    }
                    .tabViewStyle(PageTabViewStyle(indexDisplayMode: .always))
                }
            )
        }.edgesIgnoringSafeArea(.all)
    }
}https://stackoverflow.com/questions/62593923
复制相似问题