问题描述
通过使用.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)
}
}
向Rectangle
或ForEach
添加另一个 .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()
:
- 如何在SwiftUI中将TabView和NavigationView一起使用?
- 添加TabView会使导航栏无法覆盖SwiftUI中的安全区域
- 在SwiftUI中使用TabView时,NavigationView无法正确显示
- 在我的NavigationView中,.edgesIgnoringSafeArea"不会将内容移到安全区域之外
- 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.
推荐答案
- 从TabView中删除.edgesIgnoringSafeArea(.all)
- 将具有屏幕宽度和高度的框架添加到TabView
- 用ScrollView包裹TabView
- 将.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无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!