[英]SwiftUI - Navigation View title is overlapping list
I have a simple list with a navigation view, where the navigation view is overlapping the list while scrolling.我有一个带有导航视图的简单列表,其中导航视图在滚动时与列表重叠。
Here is the look I want.这是我想要的样子。
Here is what I am getting with the overlap这是我得到的重叠
Here is the code这是代码
struct MedicalDashboard: View {
let menuItemData = MenuItemList()
var body: some View {
NavigationView {
List(menuItemData.items, id: \.id) { item in
MenuItemRow(menuItem: item)
}
.listStyle(.insetGrouped)
.navigationTitle("Dashboard")
.navigationBarItems(trailing:
Button(action: {
// TODO: - Pop up a sheet for the settings page.
print("User icon pressed...")
}) {
Image(systemName: "person.crop.circle").imageScale(.large)
}
)
.padding(.top)
}
}
} }
when I add padding(.top) the overlap stops but I get a different color background on the navigation当我添加填充(.top)时,重叠停止但我在导航上得到不同的颜色背景
Try this:尝试这个:
Swift迅速
struct MedicalDashboard: View {
init() {
if #available(iOS 15, *) {
let appearance = UINavigationBarAppearance()
appearance.configureWithOpaqueBackground()
UINavigationBar.appearance().standardAppearance = appearance
UINavigationBar.appearance().scrollEdgeAppearance = appearance
}
}
...
}
On Xcode 13.4, except a missing }
, without the .padding(.top)
and with a custom List
everything works like a charm for me.在 Xcode 13.4 上,除了缺少
}
,没有.padding(.top)
和自定义List
,一切对我来说都是一种魅力。
The problem might come from MenuItemList()
.问题可能来自
MenuItemList()
。
I have still updated your code by replacing .navigationBarItems
and by adding the sheet for you:我仍然通过替换
.navigationBarItems
并为您添加工作表来更新您的代码:
struct MedicalDashboard: View {
@State private var showSheet = false
var body: some View {
NavigationView {
List { // Custom list
Text("Hello")
Text("Salut")
}
.listStyle(.insetGrouped)
.navigationTitle("Dashboard")
.toolbar() { // .navigationBarItems will be deprecated
ToolbarItem(placement: .navigationBarTrailing) {
Button(action: {
showSheet.toggle()
print("User icon pressed.")
}, label: {
Image(systemName: "person.crop.circle")
})
.sheet(isPresented: $showSheet) { /* SettingsView() */ }
}
}
}
} // New
}
Edit your post and show us MenuItemList()
.编辑您的帖子并向我们展示
MenuItemList()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.