解释iOS7中的automaticAdjustsScrollViewInsets,extendedLayoutIncludesOpaqueBars,edgesForExtendedLayout之间的区别 [英] Explaining difference between automaticallyAdjustsScrollViewInsets, extendedLayoutIncludesOpaqueBars, edgesForExtendedLayout in iOS7

查看:179
本文介绍了解释iOS7中的automaticAdjustsScrollViewInsets,extendedLayoutIncludesOpaqueBars,edgesForExtendedLayout之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在阅读很多关于iOS7 UI过渡的内容。

I have been reading a lot about iOS7 UI transition.

我无法得到这三个属性 automaticAdjustsScrollViewInsets extendedLayoutIncludesOpaqueBars edgesForExtendedLayout ??

I am not able to get what these three properties automaticallyAdjustsScrollViewInsets, extendedLayoutIncludesOpaqueBars, edgesForExtendedLayout??

例如,我试图让我的视图控制器从状态栏下面开始,但我无法实现它。

For example I am trying to make my view controllers start below the status bar but I am not able to achieve it.

推荐答案

开始在iOS7中,视图控制器默认使用全屏布局。与此同时,您可以更好地控制它的视图布局,并且使用这些属性:

Starting in iOS7, the view controllers use full-screen layout by default. At the same time, you have more control over how it lays out its views, and that's done with those properties:

edgesForExtendedLayout

基本上,通过此属性,您可以设置视图的哪些边可以扩展到覆盖整个屏幕。想象一下,你将 UIViewController 推送到 UINavigationController 。当布局该视图控制器的视图时,它将从导航栏结束的位置开始,但此属性将设置视图的哪一侧(顶部,左侧,底部,右侧)可以扩展以填充整个屏幕。

Basically, with this property you set which sides of your view can be extended to cover the whole screen. Imagine that you push a UIViewController into a UINavigationController. When the view of that view controller is laid out, it will start where the navigation bar ends, but this property will set which sides of the view (top, left, bottom, right) can be extended to fill the whole screen.

让我们看一个例子:

UIViewController *viewController = [[UIViewController alloc] init];
viewController.view.backgroundColor = [UIColor redColor];
UINavigationController *mainNavigationController = [[UINavigationController alloc] initWithRootViewController:viewController];

这里你没有设置的值edgeForExtendedLayout ,因此默认值为( UIRectEdgeAll ),因此视图扩展其布局以填充整个屏幕。

Here you are not setting the value of edgesForExtendedLayout, therefore the default value is taken (UIRectEdgeAll), so the view extends its layout to fill the whole screen.

结果如下:

如您所见,红色背景延伸到导航栏和状态栏后面。

As you can see, the red background extends behind the navigation bar and the status bar.

现在,您要将该值设置为 UIRectEdgeNone ,因此您告诉视图控制器不要扩展视图以覆盖屏幕:

Now, you are going to set that value to UIRectEdgeNone, so you are telling the view controller to not extend the view to cover the screen:

UIViewController *viewController = [[UIViewController alloc] init];
viewController.view.backgroundColor = [UIColor redColor];
viewController.edgesForExtendedLayout = UIRectEdgeNone;
UINavigationController *mainNavigationController = [[UINavigationController alloc] initWithRootViewController:viewController];

结果:

automaticAdjustsScrollViewInsets

当您的视图是 UIScrollView 或类似视图时使用此属性,例如a UITableView 。您希望表格从导航栏结束的位置开始,因为如果没有,您将看不到整个内容,但同时您希望在滚动时您的表格覆盖整个屏幕。在这种情况下,将 edgesForExtendedLayout 设置为None将不起作用,因为您的表将开始滚动导航栏结束的位置,并且它不会落后于它。

This property is used when your view is a UIScrollView or similar, like a UITableView. You want your table to start where the navigation bar ends, because you wont see the whole content if not, but at the same time you want your table to cover the whole screen when scrolling. In that case, setting edgesForExtendedLayout to None won't work because your table will start scrolling where the navigation bar ends and it wont go behind it.

这是这个属性派上用场的地方,如果让视图控制器自动调整insets(将此属性设置为YES,也是默认值),它会在表的顶部添加insets,所以表格将从导航栏结束的地方开始,但滚动将覆盖整个屏幕。

Here is where this property comes in handy, if you let the view controller automatically adjust the insets (setting this property to YES, also the default value) it will add insets to the top of the table, so the table will start where the navigation bar ends, but the scroll will cover the whole screen.

这是当设置为NO时:

和YES(默认情况下):

And YES (by default):

下启动。在这两种情况下,表格滚动导航吧,但在第二种情况下(是),它将是从导航栏下方开始。

In both cases, the table scrolls behind the navigation bar, but in the second case (YES), it will start from below the navigation bar.

extendedLayoutIncludesOpaqueBars

这个值只是一个除了以前的。默认情况下,此参数设置为NO。如果状态栏是不透明的,则视图将不会扩展为包含状态栏,即使您将视图扩展到覆盖它( edgesForExtendedLayout UIRectEdgeAll )。

This value is just an addition to the previous ones. By default, this parameter is set to NO. If the status bar is opaque, the views won't be extended to include the status bar, even if you extend your view to cover it (edgesForExtendedLayout to UIRectEdgeAll).

如果将值设置为YES,这将允许视图再次位于状态栏下方。

If you set the value to YES, this will allow the view to go underneath the status bar again.

如果问题不明确,请写一条评论然后我会回答。

If something is not clear, write a comment and I'll answer it.

iOS如何知道什么是UIScrollView?

iOS抓取ViewController视图中的第一个子视图,索引为0的子视图,以及它是<$ c $的子类c> UIScrollView 然后将解释的属性应用于它。

iOS grabs the first subview in your ViewController's view, the one at index 0, and if it's a subclass of UIScrollView then applies the explained properties to it.

当然,这意味着 UITableViewController 默认工作(因为 UITableView 是第一个观点。)

Of course, this means that UITableViewController works by default (since the UITableView is the first view).

这篇关于解释iOS7中的automaticAdjustsScrollViewInsets,extendedLayoutIncludesOpaqueBars,edgesForExtendedLayout之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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