Проблема заключается в том, что фон панели TabView не является единообразным, когда пользователь перемещается по нему. приложение. Иногда он становится прозрачным.
Я думаю, это связано с тем, как TabView отображается при прокрутке края, но я не могу исправить это.
Ниже приведен фрагмент кода, позволяющий понять структуру приложения
Код: Выделить всё
struct MainView: View {
var body: some View {
VStack(spacing: 0) {
HeaderView(viewModel: viewModel)
TabView (){
NavigationStack {
ListOfActs(viewModel: viewModel)
.navigationBarHidden(true)
}
.background(Color.colorPrimaryDark)
.tabItem {
Label("Library", systemImage: "book")
}
NavigationStack {
CollectionFrontPage(viewModel: viewModel)
.navigationBarHidden(true)
}
.tabItem {
Label("Collections", systemImage: "ellipsis.curlybraces")
}
NavigationStack {
Search(viewModel: viewModel)
}
.tabItem {
Label("Search", systemImage: "magnifyingglass")
}
NavigationStack {
InfoFrontPage(viewModel: viewModel)
.navigationBarHidden(true)
}
.tabItem {
Label("Info", systemImage: "info.circle")
}
}
}
.toolbar(.visible, for: .tabBar)
.toolbarBackground(Color.colorPrimaryDark, for: .tabBar)
.accentColor(.white)
.navigationBarHidden(true)
}
}
Код: Выделить всё
.toolbar(.visible, for: .tabBar)
.toolbarBackground(Color.colorPrimaryDark, for: .tabBar)
Ниже это упрощенная версия моего файла поиска
Код: Выделить всё
struct Search: View {
@State private var searchText = ""
var body: some View {
var searchResultDictionary: [(key: String, value: [Data])] {
//Builds an array of tuples for search results on detecting searchText changing
}
NavigationStack {
VStack {
ScrollView {
LazyVStack(pinnedViews: [.sectionHeaders]) {
ForEach(searchResultDictionary, id: \.key) { act, dataGroup in
Section(header: SectionHeaderView(stringToDisplay: act) {
ForEach(dataGroup, id: \.uniqueID) { entry in
NavigationLink(destination: DataView(uniqueID: entry.uniqueID) {
DataViewInList(data: entry)
.listRowSeparator(.hidden)
.padding(.vertical, 5)
.padding(.horizontal)
}
.buttonStyle(PlainButtonStyle())
}
.listStyle(PlainListStyle())
}
}
}
}
.searchable(text: $searchText, placement: .automatic)
}
}
.toolbar(.visible, for: .tabBar)
.toolbarBackground(Color.colorPrimaryDark, for: .tabBar)
}
}
Код: Выделить всё
.toolbar(.visible, for: .tabBar)
.toolbarBackground(Color.colorPrimaryDark, for: .tabBar)
Я также пытался добавить следующее в точку входа @main приложения:
Код: Выделить всё
init() {
// Configure the tab bar appearance globally
let appearance = UITabBarAppearance()
appearance.configureWithOpaqueBackground()
appearance.backgroundColor = UIColor(Color.colorPrimaryDark)
// Customize tab bar items appearance if needed
appearance.stackedLayoutAppearance.selected.iconColor = UIColor.white
appearance.stackedLayoutAppearance.selected.titleTextAttributes = [.foregroundColor: UIColor.white]
appearance.stackedLayoutAppearance.normal.iconColor = UIColor.gray
appearance.stackedLayoutAppearance.normal.titleTextAttributes = [.foregroundColor: UIColor.gray]
// Apply the appearance to the tab bar globally
UITabBar.appearance().standardAppearance = appearance
UITabBar.appearance().scrollEdgeAppearance = appearance
}
Проблема определенно связана с содержимым в главном представлении. Например, экран поиска при первой загрузке имеет прозрачный TabView, но если вы выполняете поиск и экран заполняется результатами (взаимодействуя с TabView), полоса возвращается к цвету ColorPrimaryDark.
Любой помощь будет оценена по достоинству!
Подробнее здесь: https://stackoverflow.com/questions/786 ... navigation
Мобильная версия