我正在创建一个像TikTok一样的全页垂直滚动。
我可以使用以下代码来实现:
struct ViewA: View {
let colors: [Color] = [ .red, .green, .blue, .gray ]
var body: some View {
GeometryReader { proxy in
TabView {
ForEach(colors, id: \.self) { color in
ZStack {
color
VStack {
Text("Hello World")
}
}
}
.rotationEffect(.degrees(-90))
.frame(
width: proxy.size.width,
height: proxy.size.height
)
}
.frame(
width: proxy.size.height,
height: proxy.size.width
)
.rotationEffect(.degrees(90), anchor: .topLeading)
.offset(x: proxy.size.width)
.tabViewStyle(
PageTabViewStyle(indexDisplayMode: .never)
)
}
}
}
但是,当我使用.edgesIgnoringSafeArea(.top)
删除顶部的安全区域(使内容填充整个屏幕,包括安全区域)时,我的内容的宽度缩小了一点。
var body: some View {
GeometryReader { proxy in
TabView {
ForEach(colors, id: \.self) { color in
ZStack {
color
VStack {
Text("Hello World")
}
}
}
.rotationEffect(.degrees(-90))
.frame(
width: proxy.size.width,
height: proxy.size.height
)
}
.frame(
width: proxy.size.height,
height: proxy.size.width
)
.rotationEffect(.degrees(90), anchor: .topLeading)
.offset(x: proxy.size.width)
.tabViewStyle(
PageTabViewStyle(indexDisplayMode: .never)
)
}
.edgesIgnoringSafeArea(.top) <----- This line causes the problem
}
我对原生ios开发非常陌生,请帮助。TIA~!
1条答案
按热度按时间vngu2lb81#
您可以尝试使用以下代码,其中包括一个
.edgesIgnoringSafeArea(.vertical)
行和一些代码行的注解。希望能帮到你。
结果: