First ViewController from Tabbar cover the safe area(Status bar)

给你一囗甜甜゛ 提交于 2020-06-29 05:04:53

问题


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)

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

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

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 = [] 

回答1:


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.

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


来源:https://stackoverflow.com/questions/62496238/first-viewcontroller-from-tabbar-cover-the-safe-areastatus-bar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!