iOS:状态栏和导航栏:空格或底层
Posted
技术标签:
【中文标题】iOS:状态栏和导航栏:空格或底层【英文标题】:iOS: Status bar and Navigation bar: Space or Underlaying 【发布时间】:2013-08-05 13:26:57 【问题描述】:如何以规范的方式操作状态栏和导航?
所以,我的目标是同时隐藏和显示状态栏和导航栏。
我应该以规范的方式做什么,避免它们之间的空间,避免底层(状态栏位于导航栏上)并支持正常旋转?
我玩过它,现在我有代码了:
-(void)tryToManipulateWithTopBarsIsHidden:(BOOL)hidden
if (self.wantsFullScreenLayout)
// Get status bar height if visible
CGFloat statusBarHeight = 0;
[self topBarsHiddenStateAppearingOrDisappearingStatusBarHidden:hidden
navigationBarHidden:hidden];
// Get status bar height if visible
if (![UIApplication sharedApplication].statusBarHidden)
CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
statusBarHeight = MIN(statusBarFrame.size.height, statusBarFrame.size.width);
// statusBarOrigin = MIN(statusBarFrame.origin.x,statusBarFrame.origin.y);
// Set navigation bar frame
// if status bar is visible and
// nav bar origin in y is not the same as status bar (magic, really)
// we need to set nav bar origin y to status bar origin y (auto shifting to bottom)
CGRect navBarFrame = self.navigationController.navigationBar.frame;
// if status bar is visible
if (![UIApplication sharedApplication].statusBarHidden)
navBarFrame.origin.y = statusBarHeight;
navBarFrame = CGRectOffset(navBarFrame, 0.0, -20.0);
self.navigationController.navigationBar.frame = navBarFrame;
self.navigationController.navigationBar.hidden =[UIApplication sharedApplication].statusBarHidden ;
LogRect(@"this is statusBar ", [UIApplication sharedApplication].statusBarFrame);
LogRect(@"this is navigationBar ", navBarFrame);
- (void)setTopBarStatusBarHidden:(BOOL)hidden onCompletion:(void(^)(UINavigationBar*))completion andNavigationBar:(UINavigationBar*)bar
[[UIApplication sharedApplication] setStatusBarHidden:hidden];
completion(bar);
- (void)setTopBarNavBarHidden:(BOOL)hidden
[self.navigationController setNavigationBarHidden:hidden animated:NO];
- (void)topBarsHiddenStateAppearingOrDisappearingStatusBarHidden:(BOOL)statusBarHidden
navigationBarHidden:(BOOL)navigationBarHidden
UINavigationBar* bar = self.navigationController.navigationBar;
id fles = self;
[self setTopBarStatusBarHidden:statusBarHidden
onCompletion:^(UINavigationBar *bar)
if (statusBarHidden)
[fles setTopBarNavBarHidden:navigationBarHidden];
else
[fles setTopBarNavBarHidden:navigationBarHidden];
andNavigationBar:bar];
但是什么都没有!
任何人都可以解释如何在没有这种混乱(真的不工作的代码)的情况下解决这个任务吗?
【问题讨论】:
【参考方案1】:你只要写在方法里:
self.navigationController.navigationBar.hidden = YES;
[UIApplication sharedApplication].statusBarHidden = YES;
这将同时隐藏导航栏和状态栏。
【讨论】:
请阅读我的问题:我想将它们隐藏/显示在一起,没有空间和底层 看看这里:***.com/questions/57517803/… 它可能对你有帮助。它对我没有任何作用。我尝试了列出的所有解决方案。有些人找到了成功。这是为 SwiftUI 设计的。以上是关于iOS:状态栏和导航栏:空格或底层的主要内容,如果未能解决你的问题,请参考以下文章
iOS 7,状态栏和导航栏:像 Reeder 一样使用侧面板隐藏或滑动