自定义UITabBarController内部的导航视图格式

时间:2020-05-09 20:12:52

标签: swift uikit swiftui bottomnavigationview uitabview

我创建了一个自定义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下:

enter image description here

要注意的另一件事:问题似乎与NavigationView有关。删除后,灰色条消失

它似乎源于UINavigationControllerenter image description here

1 个答案:

答案 0 :(得分:0)

我可以告诉你如何亲自回答这个问题...

要弄清楚该灰色区域是什么,只需在其上点击(在模拟器上,或者在您的设备上,如果您正在从Xcode上运行该应用程序),请翻转到Xcode ...

Open Debugger 从顶部菜单中选择“调试/查看调试/捕获视图层次结构”

右键单击该字段(应该很容易找到,因为您刚刚选择了它)

选择“在Debug Navigator中显示”

Reveal in Navigator

现在,您可以单击左侧的任何内容以找到更多信息... Debug on left