本文介绍了带有 PageTabViewStyle 的 TabView 上的edgesIgnoringSafeArea 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过使用 .tabViewStyle(PageTabViewStyle()) 将 TabView 用作网页浏览器工作正常,但尝试通过应用 edgesIgnoringSafeArea 让它从边缘运行到边缘不会似乎工作.

Using a TabView as a pageviewer by using .tabViewStyle(PageTabViewStyle()) works fine, but trying to let it run from edge to edge by applying edgesIgnoringSafeArea does not seem to work.

我在这里遗漏了什么?

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)
    }
}

RectangleForEach 添加另一个 .edgesIgnoringSafeArea(.all) 也不起作用.

Adding another .edgesIgnoringSafeArea(.all) to the Rectangle or ForEach also doen't work.

请注意,所有这些问题都是不同的,因为它们使用PageTabViewStyle():

Note that all these questions are different because they do not use use PageTabViewStyle():

他们的解决方案(添加 edgesIgnoringSafeArea(.all))在这种情况下不起作用.

Their solution (adding edgesIgnoringSafeArea(.all)) doesn't work in this case.

推荐答案

  1. 从 TabView 中删除 .edgesIgnoringSafeArea(.all)
  2. 为具有屏幕宽度和高度的 TabView 添加框架
  3. 用 ScrollView 包裹一个 TabView
  4. 将 .edgesIgnoringSafeArea(.all) 添加到 ScrollView
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)
    }
}

这篇关于带有 PageTabViewStyle 的 TabView 上的edgesIgnoringSafeArea 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-20 02:52