objective-c 全屏 UIView,顶部有状态栏和导航栏覆盖

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/373791/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 20:59:53  来源:igfitidea点击:

Fullscreen UIView with Status bar and Navigation Bar overlay on the top

objective-ciphone

提问by leonho

What is the proper way to implement the status bar and navigation bar that go on top of an UIView?

实现 UIView 顶部的状态栏和导航栏的正确方法是什么?

alt text http://img.skitch.com/20081217-t78sdixk37hqgdh1ia2fgec4st.png

替代文字 http://img.skitch.com/20081217-t78sdixk37hqgdh1ia2fgec4st.png

回答by Jonathan Sterling

Just set “wants fullscreen layout” in your view controller. That solves the problem for me.

只需在您的视图控制器中设置“想要全屏布局”。这为我解决了问题。

self.wantsFullScreenLayout = YES;

回答by August

In the screenshot above, there's a translucent status bar and a translucent navigation bar.

在上面的屏幕截图中,有一个半透明的状态栏和一个半透明的导航栏。

The status bar is set using

状态栏设置使用

[[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleBlackTranslucent];

The navigation bar is set using

导航栏设置使用

theNavigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;

回答by Unfalkster

If you have a view controller inside a navigation controller, and you want to hide the status bar in order to have your viewController's view in full screen, you can always call :

如果您在导航控制器中有一个视图控制器,并且您想隐藏状态栏以使 viewController 的视图全屏显示,您可以随时调用:

[self.navigationController.view setNeedsLayout];

after hiding the status bar. But I personally think

隐藏状态栏后。但我个人认为

[self setWantsFullScreenLayout:YES];

is a better way.

是更好的方法。

回答by Alfons

The best way I came up was this: when using a "complex" hierarchy of Tab bar containing navigation controllers, with one "detail" view being a full screen view.

我想出的最好方法是:使用包含导航控制器的 Tab 栏的“复杂”层次结构时,一个“详细信息”视图是全屏视图。

In the app delegate just before the tab bar controller's view is added to the window, I added this:

在将选项卡栏控制器的视图添加到窗口之前的应用程序委托中,我添加了以下内容:

tabBarController.view.frame = [[UIScreen mainScreen] bounds];

This will make the tab bar controller cover the entire screen, even below the area of the status bar. I had to offset heights of several views to +20px, notably the navigation bars.

这将使标签栏控制器覆盖整个屏幕,甚至低于状态栏区域。我不得不将几个视图的高度偏移到 +20px,尤其是导航栏。

回答by Preejith augustine

step 1 Set the UIViewControllerBasedStatusBarAppearance to No in the plist

步骤 1 在 plist 中将 UIViewControllerBasedStatusBarAppearance 设置为 No

Then add the following code in did finish launch option

然后在 did finish 启动选项中添加以下代码

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {

   [application setStatusBarStyle:UIStatusBarStyleLightContent];

    self.window.clipsToBounds =YES;

    self.window.frame =  CGRectMake(0,20,self.window.frame.size.width,self.window.frame.size.height-20);
}

Please follow this code it worked for me

请按照此代码对我有用

回答by lostInTransit

Set the statusbar style as black translucent and navigation bar style as black translucent. If you are using a navigation-based application, in the MainWindow.xib check the status bar is hidden and navigation bar is hidden checkboxes.

将状态栏样式设置为黑色半透明,将导航栏样式设置为黑色半透明。如果您使用的是基于导航的应用程序,请在 MainWindow.xib 中检查状态栏是否隐藏和导航栏是否隐藏复选框。

When the user touches the screen, start a timer to see if this was a single tap or double tap. If a single tap, make the statusbar and navbar hidden = NO. and once user activity stops, start a timer again. after some time of no activity, make them hidden again.

当用户触摸屏幕时,启动计时器以查看这是单击还是双击。如果单击一下,使状态栏和导航栏隐藏 = NO。一旦用户活动停止,再次启动计时器。一段时间没有活动后,再次隐藏它们。