解释 iOS7 中自动调整滚动视图插入、扩展布局包含不透明条、边缘ForExtendedLayout 之间的区别 [英] Explaining difference between automaticallyAdjustsScrollViewInsets, extendedLayoutIncludesOpaqueBars, edgesForExtendedLayout in iOS7

查看:30
本文介绍了解释 iOS7 中自动调整滚动视图插入、扩展布局包含不透明条、边缘ForExtendedLayout 之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了很多关于 iOS7 UI 转换的文章.

I have been reading a lot about iOS7 UI transition.

automaticallyAdjustsScrollViewInsetsextendedLayoutIncludesOpaqueBarsedgesForExtendedLayout这三个属性我无法获取到什么??

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];

这里没有设置 edgesForExtendedLayout 的值,因此采用默认值 (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];

结果:

自动调整ScrollViewInsets

当您的视图是 UIScrollView 或类似视图时使用此属性,例如 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 添加到 table 的顶部,因此 table 将启动导航栏结束的地方,但滚动会覆盖整个屏幕.

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的时候:

This is when is set to NO:

是(默认情况下):

在这两种情况下,表格都在导航栏后面滚动,但在第二种情况下(是),它将从导航栏下方开始.

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.如果状态栏是不透明的,即使您将视图扩展到覆盖状态栏,视图也不会扩展到包含状态栏(edgesForExtendedLayoutUIRectEdgeAll).

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 处的子视图,如果它是 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 中自动调整滚动视图插入、扩展布局包含不透明条、边缘ForExtendedLayout 之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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