状态栏和导航栏显示在iOS 7中的视图边界上 [英] Status bar and navigation bar appear over my view's bounds in iOS 7

查看:92
本文介绍了状态栏和导航栏显示在iOS 7中的视图边界上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近下载了 Xcode 5 DP来测试我在iOS 7中的应用。我首先要做的事情是注意到并确认是我的视图边界并不总是调整为状态栏和导航栏的大小。

I recently downloaded Xcode 5 DP to test my apps in iOS 7. The first thing I noticed and confirmed is that my view's bounds is not always resized to account for the status bar and navigation bar.

viewDidLayoutSubviews ,我打印视图的边界:

In viewDidLayoutSubviews, I print the view's bounds:


{{0,0},{320,568}}

{{0, 0}, {320, 568}}

这导致我的内容出现在导航栏和状态栏下方。

This results in my content appearing below the navigation bar and status bar.

我知道我可以通过获取主屏幕的高度,减去状态栏的高度和导航栏的高度来计算身高,但这似乎是不必要的额外工作。

I know I could account for the height myself by getting the main screen's height, subtracting the status bar's height and navigation bar's height, but that seems like unnecessary extra work.

我该如何解决这个问题问题?

How can I fix this issue?

更新:

我找到了针对此特定的解决方案问题。将导航栏的半透明属性设置为NO:

I've found a solution for this specific problem. Set the navigation bar's translucent property to NO:

self.navigationController.navigationBar.translucent = NO;

这将修复视图在导航栏和状态栏下面的框架。

This will fix the view from being framed underneath the navigation bar and status bar.

但是,当您希望导航栏为半透明时,我还没有找到针对此案例的修复程序。例如,全屏查看照片,我希望导航栏是半透明的,并且要在其下面构建视图。这是有效的,但当我切换显示/隐藏导航栏时,我经历了甚至更奇怪的结果。第一个子视图(UIScrollView)每次更改其边界y原点。

However, I have not found a fix for the case when you want the navigation bar to be translucent. For instance, viewing a photo full screen, I wish to have the navigation bar translucent, and the view to be framed underneath it. That works, but when I toggle showing/hiding the navigation bar, I've experienced even stranger results. The first subview (a UIScrollView) gets its bounds y origin changed every time.

推荐答案

您可以通过实现新属性来实现此目的在iOS7 SDK中调用 edgesForExtendedLayout 。请添加以下代码来实现此目的,

You can achieve this by implementing a new property called edgesForExtendedLayout in iOS7 SDK. Please add the following code to achieve this,

if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
        self.edgesForExtendedLayout = UIRectEdgeNone;

您需要在 - (void)viewDidLoad中添加以上内容方法。


iOS 7对如何布局和自定义外观进行了一些更改> UI 。视图控制器布局,色调
颜色和字体的更改会影响应用程序中的所有 UIKit 对象。另外,在
中,手势识别器API的增强功能可让您对手势交互进行更精细的
粒度控制。

iOS 7 brings several changes to how you layout and customize the appearance of your UI. The changes in view-controller layout, tint color, and font affect all the UIKit objects in your app. In addition, enhancements to gesture recognizer APIs give you finer grained control over gesture interactions.

使用视图控制器

在iOS 7中,视图控制器使用全屏布局。与此同时,
iOS 7让您可以更精细地控制视图控制器
布局视图的方式。特别是,全屏布局
的概念已被改进,让视图控制器指定其视图的每个
边缘的布局。

In iOS 7, view controllers use full-screen layout. At the same time, iOS 7 gives you more granular control over the way a view controller lays out its views. In particular, the concept of full-screen layout has been refined to let a view controller specify the layout of each edge of its view.

wantsFullScreenLayout 视图控制器属性在
iOS 7中已弃用。如果您当前指定 wantsFullScreenLayout = NO ,视图
控制器在iOS 7中运行时可能会在意外的屏幕位置
显示其内容。

The wantsFullScreenLayout view controller property is deprecated in iOS 7. If you currently specify wantsFullScreenLayout = NO, the view controller may display its content at an unexpected screen location when it runs in iOS 7.

调整视图控制器的布局方式它的观点, UIViewController
提供以下属性:

To adjust how a view controller lays out its views, UIViewController provides the following properties:


  • edgesForExtendedLayout

  • edgesForExtendedLayout

edgesForExtendedLayout 属性使用 UIRectEdge 类型,
指定每个矩形的四个边,除了
指定none和all之外。使用 edgesForExtendedLayout 指定视图的哪些
边缘应该扩展,而不管条形半透明度。默认为
,此属性的值为 UIRectEdgeAll

The edgesForExtendedLayout property uses the UIRectEdge type, which specifies each of a rectangle’s four edges, in addition to specifying none and all. Use edgesForExtendedLayout to specify which edges of a view should be extended, regardless of bar translucency. By default, the value of this property is UIRectEdgeAll.


  • extendedLayoutIncludesOpaqueBars

  • extendedLayoutIncludesOpaqueBars

如果您的设计使用不透明条形,请优化 edgesForExtendedLayout by
还将 extendedLayoutIncludesOpaqueBars 属性设置为
NO 。 (默认值 extendedLayoutIncludesOpaqueBars 。)

If your design uses opaque bars, refine edgesForExtendedLayout by also setting the extendedLayoutIncludesOpaqueBars property to NO. (The default value of extendedLayoutIncludesOpaqueBars is NO.)


  • automaticAdjustsScrollViewInsets

  • automaticallyAdjustsScrollViewInsets

如果您不希望滚动视图的内容插入自动为
调整,设置 automaticAdjustsScrollViewInsets 。 (
默认值 automaticAdjustsScrollViewInsets 。)

If you don’t want a scroll view’s content insets to be automatically adjusted, set automaticallyAdjustsScrollViewInsets to NO. (The default value of automaticallyAdjustsScrollViewInsets is YES.)


  • topLayoutGuide,bottomLayoutGuide

  • topLayoutGuide, bottomLayoutGuide

topLayoutGuide bottomLayoutGuide 属性指示视图控制器视图中顶部或底部条形边缘的
位置。
如果条形图应该与视图的顶部或底部重叠,则可以使用
Interface Builder通过在的底部创建
约束来相对于条形定位视图topLayoutGuide

bottomLayoutGuide的顶部。 (如果没有条形图与视图重叠,则
topLayoutGuide 的底部与视图顶部和
<$ c的顶部相同$ c> bottomLayoutGuide 与视图底部相同。)两个
属性在请求时都是懒惰创建的。

The topLayoutGuide and bottomLayoutGuide properties indicate the location of the top or bottom bar edges in a view controller’s view. If bars should overlap the top or bottom of a view, you can use Interface Builder to position the view relative to the bar by creating constraints to the bottom of topLayoutGuide or to the top of bottomLayoutGuide. (If no bars should overlap the view, the bottom of topLayoutGuide is the same as the top of the view and the top of bottomLayoutGuide is the same as the bottom of the view.) Both properties are lazily created when requested.

请参阅, apple doc

这篇关于状态栏和导航栏显示在iOS 7中的视图边界上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆