swiftui - 将视图固定到屏幕底部并忽略底部安全区域
问题描述
布局问题 - 如何设置视图块以扩展底部安全区域?我查看了 ignoresSafeAreas() 的各种来源,但无法达到我想要的结果。稍后,我希望能够向上扩展此视图,但要简短。如果这是有道理的。
var body: some View {
VStack{
Spacer()
HStack(alignment: .center) {
Text ("Expand to fill bottom safe area ...?")
.foregroundColor(.white)
}
.frame(minWidth: 100, maxWidth: .infinity, minHeight: 50, maxHeight: 100)
.background(Color.red)
.ignoresSafeArea()
}
}
解决方案
选项1
放在ignoresSafeArea
里面background
。这将使红色延伸到设备边缘,但HStack
' 的位置将保持不变。
struct ContentView: View {
var body: some View {
VStack{
Spacer()
HStack(alignment: .center) {
Text ("Expand to fill bottom safe area ...?")
.foregroundColor(.white)
}
.frame(minWidth: 100, maxWidth: .infinity, minHeight: 50, maxHeight: 100)
.background(Color.red.ignoresSafeArea()) /// inside `background`
}
}
}
选项 2
穿上ignoresSafeArea
,VStack
一切都会忽略安全区域。
struct ContentView: View {
var body: some View {
VStack{
Spacer()
HStack(alignment: .center) {
Text ("Expand to fill bottom safe area ...?")
.foregroundColor(.white)
}
.frame(minWidth: 100, maxWidth: .infinity, minHeight: 50, maxHeight: 100)
.background(Color.red)
}
.ignoresSafeArea() /// attached to `VStack`
}
}
结果:
推荐阅读
- elasticsearch - ElasticSearch:如何更新索引中的特定值
- javascript - 与 JS 交互越多,表格不会更新值
- html - SVG 缩放并保持其相对于 div 的位置
- android - 错误:程序类型已存在:com.google.android.material.appbar.AppBarLayout$1
- javascript - Angular将多个文件转换为base64字符串
- java - 检查图形是否是循环的
- mysql - 在 Spring 中保存后获取 AutoIncrement 值
- java - 即使在实施 Stackoverflow 答案后也无法解析 .andExpect() 方法
- excel - VBA:将数据从 Excel 行传输到另一个工作簿中的特定单元格,另存为并循环到下一行。
- oracle - PLSQL:将一个函数返回的数组分配给另一个函数中定义的数组