Swiftui 在我的导航视图中';。边缘识别安全区域';不将内容移过安全区域
我希望.edgesIgnoringSafeArea(.all)能够将内容正好放在画布的顶部 我希望它能像这样展示: 相反,它显示如下: 内容视图:Swiftui 在我的导航视图中';。边缘识别安全区域';不将内容移过安全区域,swiftui,Swiftui,我希望.edgesIgnoringSafeArea(.all)能够将内容正好放在画布的顶部 我希望它能像这样展示: 相反,它显示如下: 内容视图: TabView { NavigationView { MainContentView() } ... } var body: some View { VStack(alignment: .leading, spacing: 20) { ... }
TabView {
NavigationView {
MainContentView()
}
...
}
var body: some View {
VStack(alignment: .leading, spacing: 20) {
...
}
.padding([.horizontal, .top])
.navigationBarTitle("Title")
}
struct PostDetail: View {
var post: Post
var body: some View {
List {
Image(post.imageName)
.resizable()
.aspectRatio(contentMode: .fit)
.listRowInsets(EdgeInsets())
VStack(spacing: 20) {
Text(post.name)
.foregroundColor(.primary)
.font(.largeTitle)
.fontWeight(.bold)
Text(post.description)
.foregroundColor(.primary)
.font(.body)
.lineLimit(nil)
.lineSpacing(12)
VStack {
HStack {
Spacer()
ViewMoreButton(post: post)
Spacer()
}
}
}
.padding(.top)
.padding(.bottom)
}
.edgesIgnoringSafeArea(.top) //Does nothing!
.navigationBarHidden(true) // Does nothing!
}
}
主要内容视图:
TabView {
NavigationView {
MainContentView()
}
...
}
var body: some View {
VStack(alignment: .leading, spacing: 20) {
...
}
.padding([.horizontal, .top])
.navigationBarTitle("Title")
}
struct PostDetail: View {
var post: Post
var body: some View {
List {
Image(post.imageName)
.resizable()
.aspectRatio(contentMode: .fit)
.listRowInsets(EdgeInsets())
VStack(spacing: 20) {
Text(post.name)
.foregroundColor(.primary)
.font(.largeTitle)
.fontWeight(.bold)
Text(post.description)
.foregroundColor(.primary)
.font(.body)
.lineLimit(nil)
.lineSpacing(12)
VStack {
HStack {
Spacer()
ViewMoreButton(post: post)
Spacer()
}
}
}
.padding(.top)
.padding(.bottom)
}
.edgesIgnoringSafeArea(.top) //Does nothing!
.navigationBarHidden(true) // Does nothing!
}
}
详细视图:
TabView {
NavigationView {
MainContentView()
}
...
}
var body: some View {
VStack(alignment: .leading, spacing: 20) {
...
}
.padding([.horizontal, .top])
.navigationBarTitle("Title")
}
struct PostDetail: View {
var post: Post
var body: some View {
List {
Image(post.imageName)
.resizable()
.aspectRatio(contentMode: .fit)
.listRowInsets(EdgeInsets())
VStack(spacing: 20) {
Text(post.name)
.foregroundColor(.primary)
.font(.largeTitle)
.fontWeight(.bold)
Text(post.description)
.foregroundColor(.primary)
.font(.body)
.lineLimit(nil)
.lineSpacing(12)
VStack {
HStack {
Spacer()
ViewMoreButton(post: post)
Spacer()
}
}
}
.padding(.top)
.padding(.bottom)
}
.edgesIgnoringSafeArea(.top) //Does nothing!
.navigationBarHidden(true) // Does nothing!
}
}
因此,基本上,这是您的视图(提示,始终尝试发布一个人们可以复制并粘贴到Xcode中的最低版本):
struct ContentView:View{
var body:一些观点{
TabView{
导航视图{
VStack(对齐:。前导,间距:20){
名单{
图像(“背景”)
.可调整大小()
.aspectRatio(内容模式:.fit)
.listRowInsets(EdgeInsets())
}
.edgesIgnoringSafeArea(.top)
.navigationBarHidden(真)
}
.navigationBarTitle(“标题”)
}
}
}
}
是的,我也看到了同样的情况:图像没有显示在顶部安全区域。删除选项卡视图后,它将按预期工作
修复方法是将.edgesIgnoringSafeArea(.top)
也添加到选项卡中
:
struct ContentView:View{
var body:一些观点{
TabView{
导航视图{
VStack(对齐:。前导,间距:20){
名单{
图像(“背景”)
.可调整大小()
.aspectRatio(内容模式:.fit)
.listRowInsets(EdgeInsets())
}
.edgesIgnoringSafeArea(.top)
.navigationBarHidden(真)
}
.navigationBarTitle(“标题”)
}
}
.edgesIgnoringSafeArea(.top)
}
}
因此,基本上,这是您的观点(提示,始终尝试发布一个人们可以复制并粘贴到Xcode中的最低版本):
struct ContentView:View{
var body:一些观点{
TabView{
导航视图{
VStack(对齐:。前导,间距:20){
名单{
图像(“背景”)
.可调整大小()
.aspectRatio(内容模式:.fit)
.listRowInsets(EdgeInsets())
}
.edgesIgnoringSafeArea(.top)
.navigationBarHidden(真)
}
.navigationBarTitle(“标题”)
}
}
}
}
是的,我也看到了同样的情况:图像没有显示在顶部安全区域。删除选项卡视图后,它将按预期工作
修复方法是将.edgesIgnoringSafeArea(.top)
也添加到选项卡中
:
struct ContentView:View{
var body:一些观点{
TabView{
导航视图{
VStack(对齐:。前导,间距:20){
名单{
图像(“背景”)
.可调整大小()
.aspectRatio(内容模式:.fit)
.listRowInsets(EdgeInsets())
}
.edgesIgnoringSafeArea(.top)
.navigationBarHidden(真)
}
.navigationBarTitle(“标题”)
}
}
.edgesIgnoringSafeArea(.top)
}
}
您必须发布一些代码,以便我们可以看到您可能做错了什么。如果您发布时正在编辑,则它是向上的。您必须发布一些代码,以便我们可以看到您可能做错了什么。如果您发布时正在编辑,则它是向上的。这正是我正在寻找的。谢谢这正是我想要的。谢谢我会把小费带到船上