微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

SwiftUI标签栏顶部的空白标签栏高度区域

如何解决SwiftUI标签栏顶部的空白标签栏高度区域

我想在UIHostingController中插入一个标签,即UITabBarController的SwiftUI视图,就像这张图片一样:

enter image description here

视图非常简单,

ContentView.swift

struct ContentView: View {
       var body: some View {
            ZStack {
                Color(.red).opacity(0.2).edgesIgnoringSafeArea(.all)
                NavigationView {
                    Text("Hello")
                }
            }
}
    

AppDelegate.swift (禁用的场景)中,我得到viewControllers并像这样插入:

let controller = UIStoryboard(name: "Main",bundle: nil).instantiateViewController(identifier: "TabBarController") as! UITabBarController
let view = ContentView()
let viewController = UIHostingController(rootView: view)
controller.viewControllers?.insert(viewController,at: 0)
let item = controller.tabBar.items![0]
item.title = "Tab"
window.rootViewController = controller
self.window = window
window.makeKeyAndVisible()

结果如上图所示,可以。但是当我将Text放入NavigationView时,就像这样:

var body: some View {
        ZStack {
            Color(.red).opacity(0.2).edgesIgnoringSafeArea(.all)
            NavigationView {
                Text("Hello")
            }
        }
}

那么结果是:

enter image description here

一个灰色的空白栏,看起来和那里的标签栏相等,如何将其删除

我尝试通过以下方式隐藏标签栏:

tabBarController.tabBar.isHidden = true

是的,它已经消失了,但是我不想隐藏tabBar。任何帮助,谢谢!

解决方法

我终于解决了,方法是删除情节提要中的UITabBarController并重新添加。旧版本由较旧的Xcode版本添加。我比较了两个UITabBarController,没有看到界面生成器的区别。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。