xcode 在视图 iOS7 上重叠状态栏

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18892500/
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-15 03:49:22  来源:igfitidea点击:

Overlaps the status bar on view iOS7

iphonexcodeios7

提问by Nirmalsinh

I have develop the my iPad application in ios6 but now i want to develop that application in ios7 also , I am using .xib file and I am not using the AutoLayout i want to use the black status bar in my application and i want to make the application similar like ios 6 but the status bar is overlap on the view i use the different code like below link

我已经在 ios6 中开发了我的 iPad 应用程序,但现在我也想在 ios7 中开发该应用程序,我使用的是 .xib 文件,我没有使用 AutoLayout 我想在我的应用程序中使用黑色状态栏,我想制作该应用程序类似于 ios 6,但状态栏在视图上重叠我使用不同的代码,如以下链接

Link 1 Position of navigation bar for modal view - iOS7

链接 1 模态视图导航栏的位置 - iOS7

Link 2 iOS 7 - Status bar overlaps the view

链接 2 iOS 7 - 状态栏与视图重叠

Thanks in Advance

提前致谢

enter image description here

在此处输入图片说明

回答by Daij-Djan

wont happen, two options:

不会发生,两种选择:

  1. use a custom background image that is sized accordingly.. IIRC 44 (for navbar) + 20 (for status bar)
  1. 使用相应大小的自定义背景图像.. IIRC 44(用于导航栏)+ 20(用于状态栏)

OR

或者

  1. account for the 20 pixels by using a custom view which is black :D
  1. 通过使用黑色的自定义视图来计算 20 个像素:D

回答by Nandha

In iOS 7, the status bar is transparent, and other bars—that is, navigation bars, tab bars, toolbars, search bars, and scope bars—are translucent. As a general rule, you want to make sure that content fills the area behind the bars in your app.

在 iOS 7 中,状态栏是透明的,其他栏——即导航栏、标签栏、工具栏、搜索栏和范围栏——是半透明的。作为一般规则,您希望确保内容填充应用程序中栏后面的区域。

Because the status bar is transparent, the view behind it shows through. The style of the status bar refers to the appearance of its content, which includes items such as time, battery charge, and Wi-Fi signal. Use a UIStatusBarStyleconstant to specify whether the status bar content should be dark (UIStatusBarStyleDefault) or light (UIStatusBarStyleLightContent):

因为状态栏是透明的,所以它后面的视图是透明的。状态栏的样式是指其内容的外观,包括时间、电池电量、Wi-Fi信号等项目。使用UIStatusBarStyle常量来指定状态栏内容是深色 ( UIStatusBarStyleDefault) 还是浅色 ( UIStatusBarStyleLightContent):

UIStatusBarStyleDefaultdisplays dark content. Use when light content is behind the status bar. UIStatusBarStyleLightContentdisplays light content. Use when dark content is behind the status bar.

UIStatusBarStyleDefault显示深色内容。当轻量内容位于状态栏后面时使用。 UIStatusBarStyleLightContent显示轻量内容。当状态栏后面有深色内容时使用。

In some cases, the background image for a navigation bar or a search bar can extend up behind the status bar. If there are no bars below the status bar, the content view should use the full height of the screen.

在某些情况下,导航栏或搜索栏的背景图像可以向上延伸到状态栏后面。如果状态栏下方没有栏,则内容视图应使用屏幕的整个高度。

In iOS 7, you can control the style of the status bar from an individual view controller and change it while the app runs. If you prefer to opt out of this behaviour and set the status bar style by using the UIApplication statusBarStylemethod, add the UIViewControllerBasedStatusBarAppearancekey to an app's Info.plistfile and give it the value NO.

在 iOS 7 中,您可以从单个视图控制器控制状态栏的样式,并在应用程序运行时更改它。如果您更喜欢选择退出此行为并使用UIApplication statusBarStyle方法设置状态栏样式,请将UIViewControllerBasedStatusBarAppearance键添加到应用程序的Info.plist文件并为其指定值NO

For more details about how to use status bar with navigation controller, please refer my answer here.

有关如何将状态栏与导航控制器一起使用的更多详细信息,请参阅我的回答here

回答by Bms270

A workaround to use the old style status bar is to modify the frame of the main view and shift it down 20px. This will only work on viewWillAppear function but you need to make sure you call this once. This is more of a hack than a solution:

使用旧样式状态栏的解决方法是修改主视图的框架并将其向下移动 20px。这仅适用于 viewWillAppear 函数,但您需要确保调用一次。这与其说是解决方案,不如说是一种黑客攻击:

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
[self.view setFrame: CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y+20, self.view.frame.size.width, self.view.frame.size.height-20)];
}

回答by spaleja

Try below to do not overwrite status bar:

尝试以下不覆盖状态栏:

[navController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navBar.png"] forBarPosition:UIBarPositionTop barMetrics:UIBarMetricsDefault];