Swift 导航栏下的快捷键空白
我有一个带有导航栏的视图,里面有一个大标题和内容。我已经更改了内容背景色和导航栏背景色Swift 导航栏下的快捷键空白,swift,swiftui,background-color,navigationbar,Swift,Swiftui,Background Color,Navigationbar,我有一个带有导航栏的视图,里面有一个大标题和内容。我已经更改了内容背景色和导航栏背景色 var body: some View { NavigationView { VStack { //content }.background(Color.green) .edgesIgnoringSafeArea(.bottom) //to fill the white space at t
var body: some View {
NavigationView {
VStack {
//content
}.background(Color.green)
.edgesIgnoringSafeArea(.bottom) //to fill the white space at the bottom
.navigationBarTitle("Wallets")
}
}
现在,如果我使用NavigationLink移动到下一个视图,并且该视图的标题为.inline显示模式(不同的NavigationBar大小),在转换的瞬间,我会看到第一个导航栏下的空白。如果我为VStack创建.edgesIgnoringSafeArea(.all),我可以填充它,但在这种情况下,我的所有内容都跳转到导航栏下。如何将导航栏下的空间着色为自定义颜色?看起来像是个bug。我没有找到正常的解决办法。以下是一个解决方法: 我们应该计算导航栏的高度并填满它后面的空间
var deviceHeight: CGFloat {
UIScreen.main.bounds.height
}
func calcPadding() -> CGFloat {
var padding: CGFloat = 0.0
switch self.deviceHeight {
case 568.0: padding = 94.0 + 6.0
case 667.0: padding = 96.0 + 10.0
case 736.0: padding = 96.0 + 10.0
case 812.0: padding = 106.0 + 10.0
case 896.0: padding = 106.0 + 10.0
default:
padding = 106.0
}
return padding
}
var body: some View {
NavigationView {
VStack {
VStack {
//content
}
.padding(.top, calcPadding())
.background(Color.myBackground)
}
.background(Color.myBackground)
.edgesIgnoringSafeArea(.all)
}
}
你成功修复了吗?我没有找到正常的解决方案,请参阅下面的解决方法。是的,很好。我正在用偏移量修正它!当您将手机旋转到横向时会发生什么情况?高度不再适用了,不是吗?这个问题没有更好的解决办法吗?
var deviceHeight: CGFloat {
UIScreen.main.bounds.height
}
func calcPadding() -> CGFloat {
var padding: CGFloat = 0.0
switch self.deviceHeight {
case 568.0: padding = 94.0 + 6.0
case 667.0: padding = 96.0 + 10.0
case 736.0: padding = 96.0 + 10.0
case 812.0: padding = 106.0 + 10.0
case 896.0: padding = 106.0 + 10.0
default:
padding = 106.0
}
return padding
}
var body: some View {
NavigationView {
VStack {
VStack {
//content
}
.padding(.top, calcPadding())
.background(Color.myBackground)
}
.background(Color.myBackground)
.edgesIgnoringSafeArea(.all)
}
}