【发布时间】:2020-03-25 16:11:55
【问题描述】:
我想要一个带有导航视图的全屏背景图像(必须在顶部,因为它来自基础视图,而不是通常在“此”视图中)。 在这个视图中,我想要一个 VStack,它位于安全区域内,位于导航栏和底部布局之间。
不幸的是我得到了(见图)
struct ContentView: View {
var body: some View {
NavigationView {
ZStack(alignment: .center) {
Image("laguna")
.resizable()
.edgesIgnoringSafeArea(.all)
.scaledToFill()
.frame(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)
VStack(alignment: .center) {
Text("just a test")
.font(.largeTitle)
.foregroundColor(Color.white)
Spacer()
Text ("not centered....why?")
.font(.largeTitle)
.foregroundColor(Color.white)
}
.zIndex(4)
.navigationBarTitle("nav bar title")
}
}
}
}
【问题讨论】: