简体   繁体   English

iOS 7-状态栏与视图内容重叠

[英]iOS 7 - Status bar overlaps the view content

我在我的应用程序中使用状态栏,并希望维持ios 6和ios 7之间的兼容性。我希望状态栏的行为与ios 6相同。我不希望状态栏与视图控制器重叠。

Try adding the following code in your view's viewWillAppear function: 尝试在视图的viewWillAppear函数中添加以下代码:

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    // if this is ios7 this code will make the view appear properly below the navigation bar
    if ([[UIDevice currentDevice].systemVersion floatValue] >= 7.0) {
        self.edgesForExtendedLayout = UIRectEdgeNone;
        self.extendedLayoutIncludesOpaqueBars = YES;
    }
}

Try this~ 试试这个〜

if(OVER_IOS7){
    self.edgesForExtendedLayout = UIRectEdgeNone;
    [self.navigationController.navigationBar setTranslucent:NO]
}

Try this. 尝试这个。

add this key into info.plist file 将此密钥添加到info.plist文件中

View controller-based status bar appearance 查看基于控制器的状态栏外观

set value for this to:- No 将此值设置为:-否

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. 在iOS 7中,状态栏是透明的,其他栏(即导航栏,标签栏,工具栏,搜索栏和范围栏)是半透明的。 As a general rule, you want to make sure that content fills the area behind the bars in your app. 通常,您要确保内容填充应用程序中条形图后面的区域。

Most bars also draw a blur behind them, unless you provide a custom background image for the bar. 除非您为条形图提供自定义背景图像,否则大多数条形图也会在其后绘制模糊效果。

iOS 7 introduces the barPosition property for identifying bar position, which helps you specify when a custom background image should extend behind the status bar. iOS 7引入了barPosition属性来标识条的位置,该属性可帮助您指定何时应将自定义背景图像延伸到状态栏的后面。 The UIBarPositionTopAttached value means that a bar is at the top of the screen and its background extends upward into the status bar area. UIBarPositionTopAttached值表示一个条位于屏幕顶部,其背景向上延伸到状态条区域。 In contrast, the UIBarPositionTop value means that a bar is at the top of its local context—for example, at the top of a popover—and that it doesn't provide a background for the status bar. 相反,UIBarPositionTop值表示栏位于其本地上下文的顶部(例如,在弹出窗口的顶部),并且不为状态栏提供背景。

By default, all bar buttons are borderless. 默认情况下,所有的条形按钮都是无边界的。 For details, see Bar Buttons. 有关详细信息,请参见“条形按钮”。

The Status Bar 状态栏

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. 状态栏的样式表示其内容的外观,其中包括诸如时间,电池电量和Wi-Fi信号之类的项目。 Use a UIStatusBarStyle constant to specify whether the status bar content should be dark (UIStatusBarStyleDefault) or light (UIStatusBarStyleLightContent): 使用UIStatusBarStyle常量可以指定状态栏内容应为深色(UIStatusBarStyleDefault)还是浅色(UIStatusBarStyleLightContent):

UIStatusBarStyleDefault displays dark content. UIStatusBarStyleDefault显示暗的内容。 Use when light content is behind the status bar. 当灯光内容在状态栏后面时使用。 image: ../Art/status_bar_default_iphone_2x.pngimage: ../Art/status_bar_default_ipad_2x.png UIStatusBarStyleLightContent displays light content. 图像:../Art/status_bar_default_iphone_2x.png图像:../Art/status_bar_default_ipad_2x.png UIStatusBarStyleLightContent显示灯光内容。 Use when dark content is behind the status bar. 当状态栏后面有深色内容时使用。 image: ../Art/status_bar_light_iphone_2x.pngimage: ../Art/status_bar_light_ipad_2x.png In some cases, the background image for a navigation bar or a search bar can extend up behind the status bar (for details, see Navigation Bar and Search Bar and Scope Bar). 图像:../Art/status_bar_light_iphone_2x.png图像:../Art/status_bar_light_ipad_2x.png在某些情况下,导航栏或搜索栏的背景图像可能会在状态栏后面延伸(有关详细信息,请参阅导航栏和搜索条和范围条)。 If there are no bars below the status bar, the content view should use the full height of the screen. 如果状态栏下方没有任何栏,则内容视图应使用屏幕的整个高度。 To learn how to ensure that a view controller lays out its views properly, see Using View Controllers. 要了解如何确保视图控制器正确地布局其视图,请参阅使用视图控制器。

In iOS 7, you can control the style of the status bar from an individual view controller and change it while the app runs. 在iOS 7中,您可以从单个视图控制器控制状态栏的样式,并在应用程序运行时对其进行更改。 If you prefer to opt out of this behavior and set the status bar style by using the UIApplication statusBarStyle method, add the UIViewControllerBasedStatusBarAppearance key to an app's Info.plist file and give it the value NO. 如果您选择退出此行为并通过使用UIApplication statusBarStyle方法设置状态栏样式,请将UIViewControllerBasedStatusBarAppearance键添加到应用程序的Info.plist文件中,并将其值设置为NO。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM