使用TabTabViewStyle的TabView上的edgeIgnoringSafeArea无法正常工作 [英] edgesIgnoringSafeArea on TabView with PageTabViewStyle not working

查看:126
本文介绍了使用TabTabViewStyle的TabView上的edgeIgnoringSafeArea无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过使用.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():

  • How do I use a TabView with a NavigationView in SwiftUI?
  • Adding a TabView makes the Navigation Bar not cover the safe area in SwiftUI
  • NavigationView doesn't display correctly when using TabView in SwiftUI
  • In my NavigationView '.edgesIgnoringSafeArea' does not move content past the safe area

在这种情况下,他们的解决方案(添加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)
    }
}

这篇关于使用TabTabViewStyle的TabView上的edgeIgnoringSafeArea无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆