Tabbar 中的第一个 ViewController 覆盖了安全区域(状态栏) [英] First ViewController from Tabbar cover the safe area(Status bar)

查看:29
本文介绍了Tabbar 中的第一个 ViewController 覆盖了安全区域(状态栏)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

After sucessful signin i am opening Tabbar with follwing code

    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 也覆盖了保存区域...

Its open Tabbar with first index selected but first ViewController also cover the save area ...

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

and switching between the TabbarItems make it work fine ...

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

I am not able to understand why this happening only in one ViewController on first time open ... and how to tackle that.

也尝试了以下代码,但没有奏效...

Also tried following code but did't work ...

self.edgesForExtendedLayout = [] 

推荐答案

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

Its not the proper solution its a kind of hack ... I told in Question that its get automatically fixed after switching between TabbarItems ... so i just added Two lines right after opening Tabbar VC.

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

并且知道完整的代码是这样的.

And know the complete code seems like this.

让 appDelegate = UIApplication.shared.delegate as!应用委托

let appDelegate = UIApplication.shared.delegate as! AppDelegate

     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

这篇关于Tabbar 中的第一个 ViewController 覆盖了安全区域(状态栏)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆