想象一下黑条上方的所有内容都是导航栏,如果向下滚动,它将始终保持在顶部。问题是我无法执行此操作,因为我有工具栏。
/// Temporary search bar, make this functional later
ToolbarItem(placement: .principal){
HStack{
Image(systemName:"magnifyingglass")
.resizable()
.scaledToFit()
.frame(width: 18, height: 18)
.foregroundStyle(.shuttleGray)
.padding(.leading, 5)
Text("Search messages")
.font(.subheadline)
.foregroundColor(.shuttleGray)
Spacer()
Image(systemName:"slider.horizontal.3")
.resizable()
.scaledToFit()
.frame(width: 18, height: 18)
.foregroundStyle(.shuttleGray)
}
.frame(maxWidth: .infinity, alignment: .leading)
.padding(8)
.background(.concrete)
.cornerRadius(10)
}
它已经占用了所有空间,在主工具栏项中添加 VStack 或其他内容似乎是一个不好的方法,而且这也限制了我拥有的分隔符矩形的宽度。有谁知道我怎样才能实现这一目标? 这也是我的焦点按钮和其他按钮+分隔符的代码
VStack{
/// Tab view for both Focused & Other tabs
/// Can see later if worth switching to Grids over this Spacer way
HStack{
Spacer()
Button{
} label: {
Text("Focused")
}
.font(.title3)
.foregroundStyle(.shuttleGray)
Spacer()
Button{
} label: {
Text("Other")
}
.font(.title3)
.foregroundStyle(.shuttleGray)
Spacer()
}
HStack(spacing: 0){
VStack(spacing:0){
Rectangle()
.frame(height: 2)
.foregroundStyle(.green)
.padding(.horizontal)
Rectangle()
.frame(height: 2)
}
Rectangle()
.frame(height: 2)
}
}
我发现这个在 SwiftUI 中的导航栏标题下方添加附件视图,这是一个修复,使用 safeAreaInset 可以工作,但仍然感觉有点奇怪,如果其他人有更干净的解决方案,我会很感激,但我想这主要是适合我!