gpt4 book ai didi

ios - 隐藏 UIStatusBar 而不移除为其分配的空间

转载 作者:搜寻专家 更新时间:2023-10-31 22:33:39 26 4
gpt4 key购买 nike

我有图片示例向您展示我想要什么以及我现在拥有什么。

首先,这是我正在尝试做的一个示例,来自 Slack 应用程序:

状态栏正常显示:

enter image description here

但是当你打开侧边抽屉时,它就消失了:

enter image description here

我可以在我的应用中显示状态栏:

enter image description here

但是当我隐藏它时,它也隐藏了框架,所以顶部的空间比以前少了:

enter image description here

每当侧边抽屉打开时从顶部移除空间看起来很奇怪,但由于菜单具有不同的背景颜色,因此不隐藏状态栏看起来也很糟糕。如何隐藏状态栏上的文本,同时保留它的空间?

最佳答案

我认为您需要类似以下内容(在 Swift 中,部署目标是 9.0):

隐藏它:

    UIApplication.sharedApplication().setStatusBarHidden(true, withAnimation: .Fade)
let appFrame:CGRect = UIScreen.mainScreen().applicationFrame

UIView.animateWithDuration(0.3, animations: {
self.navigationController?.navigationBar.frame = self.navigationController!.navigationBar.bounds
self.view.window!.frame = CGRectMake(0, 0, appFrame.size.width, appFrame.size.height);
})

再次显示:

    let appFrame:CGRect = UIScreen.mainScreen().applicationFrame
UIApplication.sharedApplication().setStatusBarHidden(false, withAnimation: .Fade)

UIView.animateWithDuration(0.3, animations: {
self.navigationController?.navigationBar.frame = self.navigationController!.navigationBar.bounds
self.view.window!.frame = CGRectMake(0, 0, appFrame.size.width, appFrame.size.height-0.00001);
})

我不确定您是否会遇到与我相同的问题,但是当我测试代码时,我最初没有那个“-0.00001”,并且过渡并不顺利,但那个小减法修复了它。不知道为什么。

关于ios - 隐藏 UIStatusBar 而不移除为其分配的空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34518815/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com