Tabbar的第一个ViewController覆盖了安全区域(状态栏)

时间:2020-06-21 08:33:48

标签: ios swift xcode statusbar tabbar

成功登录后,我将使用以下代码打开import { hasIn } from "lodash"; const Headlines = (props) => { const [state, setState] = React.useState({ status: "loading", data: [], currentSection: "" }); const filterList = ["world", "politics", "business", "technology", "sports"]; useEffect(() => { if (hasIn(props, "match.params.section") && filterList.indexOf(props.match.params.section) > -1 && currentSection !== props.match.params.section ) { props.getArticles(props.match.params.section).then((result) => { if (result.length > 0) { setState({ status: "found", data: result, currentSection: props.match.params.section }); } else { setState({ status: "notfound", data: [], currentSection: "" }); } }).catch((error) => { console.log(error); setState("notfound") }) } else { setState("notfound") } }, [props]); switch (state.status) { case "notfound": return ( <Container fluid> <h1>The page cannot be found</h1> </Container> ); case "found": return <Container fluid className={classes.headlines}> {data.map((article) => { return <HeadlineItem key={article.id} article={article} /> })} </Container> default: return <Spinner /> } };

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

enter image description here

并在ViewController之间切换可以使其正常工作...

enter image description here

我无法理解为什么这种情况仅在一次TabbarItems首次打开时发生……以及如何解决。

还尝试了以下代码,但没有用...

ViewController

1 个答案:

答案 0 :(得分:0)

它不是一种适当的解决方案,它是一种黑客手段...我在《问题》中告诉它,它在TabbarItems之间切换后会自动修复...所以我在打开Tabbar之后就添加了两行VC。

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

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

让appDelegate = UIApplication.shared.delegate为! 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