我最近更新了Xcode,由于某种原因,现在在模拟器中(以及在设备上),我的SwiftUI视图上的导航栏被切断,如下图所示:
我没有更改任何代码,所以我想知道到底发生了什么。该视图的代码供参考:
init() {
viewModel = EventsViewModel()
coloredNavAppearance.configureWithOpaqueBackground()
coloredNavAppearance.backgroundColor = ColorCodes.darkGrey.uicolor()
coloredNavAppearance.titleTextAttributes = [.foregroundColor: UIColor.white]
coloredNavAppearance.largeTitleTextAttributes = [.foregroundColor: UIColor.white]
UINavigationBar.appearance().standardAppearance = coloredNavAppearance
UINavigationBar.appearance().scrollEdgeAppearance = coloredNavAppearance
UINavigationBar.appearance().tintColor = .white
UITableView.appearance().separatorStyle = .none
}
var body: some View {
NavigationView {
ZStack {
ColorCodes.darkGrey.color()
.edgesIgnoringSafeArea(.all)
VStack {
if viewModel.eventViewModels.isEmpty {
Text("No events are active yet. Click the plus button to purchase an event.").foregroundColor(.white).font(.custom("Segoe UI", size: 17))
}else {
List{
ForEach(viewModel.eventViewModels, id: \.id) { eventViewModel in
EventRow(viewModel: eventViewModel)
}.listRowBackground(ColorCodes.darkGrey.color())
}
}
}
.navigationBarTitle(Text("Active Events"), displayMode: .large)
.navigationBarItems(trailing:
Button(action: {
//show add event modal
self.viewModel.showAddEventModal.toggle()
}) {
Image("plus")
}
)
.alert(isPresented: $viewModel.showAlert) {
Alert(title: Text("Error"), message: Text(viewModel.errorMessage), dismissButton: .default(Text("Ok")))
}
.font(.custom("Segoe UI", size: 17))
.sheet(isPresented: $viewModel.showAddEventModal) {
AddEventView(viewModel: AddEventViewModel())
}
}
}
}
我的确在班级的初始化过程中有一些自定义的导航栏外观登录名,但这在以前是非常好的。这是否发生在其他任何人身上,也没有人找到或找到解决方法吗?
您通过忽略顶部边缘安全区域(因为它是inside导航视图)来强行移动它
ZStack {
ColorCodes.darkGrey.color()
.edgesIgnoringSafeArea(.all) // << reason !!!
删除此行,或仅使用.bottom
,然后使用for NavigationView
代替内容。经过Xcode 11.4 / iOS 13.4的测试]