我想在我的 iOS v5 通用应用程序中切换状态栏。
但发现其他人似乎有 UIViews(在我的例子中是添加到主视图的 subview )如果您随后旋转设备(我正在使用模拟器),只会回收隐藏状态栏留下的 20px
我的观点是通过编程完成的。
我尝试了通过谷歌搜索找到的一些建议,但似乎都没有用。即更改自动调整大小/掩码、wantsFullScreenLayout、setNeedsLayout,在 IB 中“使用全屏”。
我终于意识到我正在将我的 View frame height 设置为 0 并将它的 bounds height 设置为 [[UIScreen mainScreen ] applicationFrame] size.height
我想到的是: 将 View frame height 设置为 -20 并将其 bounds height 设置为 [[UIScreen mainScreen] applicationFrame] size.height+20
在 viewDidLoad 中。
CGRect theDeviceRect= [[UIScreen mainScreen] applicationFrame];
newMap.frame = CGRectMake(0, -20, theDeviceRect.size.width, theDeviceRect.size.height+20);
我在 willAnimateRotationToInterfaceOrientation: 委托(delegate)中也有这个。
现在当我切换状态栏时:
- (void) toggleStatusBarAction:(id)sender{
BOOL istathidden= [[UIApplication sharedApplication] isStatusBarHidden];
[[UIApplication sharedApplication] setStatusBarHidden:!istathidden withAnimation:UIStatusBarAnimationFade];
}
一切都按预期工作。但我想看看我的解决方案是好是坏,如果我遗漏了什么?:
非常感谢。 MH
最佳答案
我做的是:
在这段代码之后:
[[UIApplication sharedApplication] setStatusBarHidden:NO];
我立即执行:
CGRect originalFrame = self.view.frame;
originalFrame.origin.y = 20.0;
self.view.frame = originalFrame;
这会将框架“刷新”到正确的位置。 不是最佳解决方案,但它有效。
在您的示例中,您可能需要根据 istathidden 将 y 动态设置为 0 或 20。
2012 年 9 月 2 日编辑: 关闭模态视图 Controller 时更好的解决方案:
[[UIApplication sharedApplication] setStatusBarHidden:NO];
self.view.frame = [[UIScreen mainScreen] applicationFrame];
关于objective-c - 当设置 setStatusBarHidden : in iOS v5 app. 时留有空白。这是修复它的正确方法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8669025/