我创建了一个自定义UITabBarController来避免SwiftUI标签栏的某些不足。查看更多here。这是我实现的地方:
import SwiftUI
struct HomeView: View {
@EnvironmentObject var appState: AppState
var body: some View {
UITabBarWrapper([
TabBarElement(tabBarElementItem:
TabBarElementItem(title: "Learn", systemImageName: "book")) {
NewsView()
},
TabBarElement(tabBarElementItem:
TabBarElementItem(title: "Matches", systemImageName: "heart")) {
MatchesTab().environmentObject(AppState())
},
TabBarElement(tabBarElementItem:
TabBarElementItem(title: "Account", systemImageName: "person")) {
ProfileView()
}
])
.frame(maxHeight: .infinity)
.edgesIgnoringSafeArea(.top)
}
}
MatchesTab()
是NavigationView
:
import SwiftUI
struct MatchesTab: View {
@EnvironmentObject var appState: AppState
@State private var showingCandidate = false
var body: some View {
NavigationView {
if self.appState.hasTakenQuiz {
MatchesTabDefaultView()
.transition(.opacity)
.animation(.default)
} else {
SplashView()
}
}
}
}
由于某种原因,此灰色空间出现在嵌入的MatchesTab
下:
要注意的另一件事:问题似乎与NavigationView
有关。删除后,灰色条消失