【问题标题】:First ViewController from Tabbar cover the safe area(Status bar)Tabbar 中的第一个 ViewController 覆盖了安全区域(状态栏)
【发布时间】:2020-06-21 08:33:48
【问题描述】:

成功登录后,我将使用以下代码打开Tabbar

    let  mainView = UIStoryboard(name:"Main", bundle: nil)
    let tabbar = mainView.instantiateViewController(withIdentifier: "Tabbar") as? Tabbar
    tabbar?.modalPresentationStyle = .fullScreen
    self.present(tabbar!, animated: true, completion: nil)

它打开Tabbar 并选择了第一个索引,但第一个ViewController 也覆盖了保存区域...

并在TabbarItems 之间切换使其正常工作...

我无法理解为什么这种情况只发生在第一次打开的ViewController 中......以及如何解决这个问题。

也尝试了以下代码,但没有工作......

self.edgesForExtendedLayout = [] 

【问题讨论】:

  • 尝试从主线程呈现
  • 看看这个StackOverflow question。
  • @FrancescoDeliro 类似的情况......但我在Xcode11.5 上创建了项目并在iOS 13.5 上运行......默认情况下它生成了该答案中给出的所有代码......

标签: ios swift xcode statusbar tabbar


【解决方案1】:

它不是正确的解决方案,它是一种黑客行为......我在问题中告诉它在 TabbarItems 之间切换后会自动修复......所以我在打开 Tabbar VC 后立即添加了两行。

       tabbar?.selectedIndex = 1
       tabbar?.selectedIndex = 0

并且知道完整的代码看起来像这样。

让 appDelegate = UIApplication.shared.delegate 为!应用代理

     let mainView = UIStoryboard(name:"Main", bundle: nil)
     let tabbar = mainView.instantiateViewController(withIdentifier: "Tabbar") as? Tabbar
     appDelegate.window = UIWindow(frame: UIScreen.main.bounds)
     appDelegate.window!.rootViewController = tabbar
     appDelegate.window!.makeKeyAndVisible()
    
     tabbar?.modalPresentationStyle = .fullScreen
     self.present(tabbar!, animated: true, completion: nil)
     tabbar?.selectedIndex = 1
     tabbar?.selectedIndex = 0

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-29
    • 2016-12-21
    • 1970-01-01
    相关资源
    最近更新 更多