0
如何使用狀態欄和導航以規範的方式進行操作?iOS:狀態欄和導航欄:空間或者下層
因此,我的目標是隱藏並出現狀態欄和導航欄的同時。
我應該以規範的方式做什麼,避免它們之間的空間,避免underlaying(狀態欄躺在導航欄上),並支持正常的旋轉?
我已經打了它,現在我有一些代碼:
-(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];
}
但沒有什麼!
任何人都可以解釋如何解決這個任務沒有這個混亂(真的不工作的代碼)?
請閱讀我的問題:我想隱藏/展示他們沒有空間和underlay – gaussblurinc