我正在开发一个带有简单导航视图和工具栏的 macCatalyst 应用程序。 一旦我给我的toolbarItem .principal 位置,工具栏的高度就会增加(几乎加倍)。在图像中,您可以看到“MyButton”和视图边框之间有很大的空间。
struct ContentView: View {
@State var toggle = false
var body: some View {
NavigationView {
VStack {
Text("Sidebar")
}
.padding()
VStack {
Spacer()
Text("Hello, world!")
Spacer()
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(.yellow)
.border(.red)
.toolbar {
ToolbarItemGroup(placement: .principal) {
Button {
toggle.toggle()
} label: {
Text("MyButton")
.foregroundColor(Color.accentColor)
}
}
}
}
}
}
当我的toolbarItem的位置是.automatic,.navigation,...高度又恢复正常了。
我长期以来一直在寻找该问题的解决方案...... 一些想法?
.navigationBarTitleDisplayMode(.inline)
(有同样的问题,在我找到答案之前就找到了你的问题)