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

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

问题描述

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

我无法获得这三个属性 automaticallyAdjustsScrollViewInsetsextendedLayoutIncludesOpaqueBarsedgesForExtendedLayout??

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

解决方案

从 iOS7 开始,视图控制器默认使用全屏布局.同时,您可以更好地控制视图的布局方式,而这正是通过这些属性完成的:

edgesForExtendedLayout

基本上,您可以使用此属性设置视图的哪一侧可以扩展以覆盖整个屏幕.想象一下,您将一个 UIViewController 推入一个 UINavigationController.当该视图控制器的视图布局时,它将从导航栏结束的地方开始,但该属性将设置视图的哪一侧(顶部、左侧、底部、右侧)可以扩展以填充整个屏幕.

举个例子:

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

这里您没有设置edgesForExtendedLayout的值,因此采用默认值(UIRectEdgeAll),因此视图扩展其布局以填充整个屏幕.

结果如下:

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

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

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

结果:

<小时>

automaticallyAdjustsScrollViewInsets

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

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

这是设置为 NO 时:

是(默认):

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

<小时>

extendedLayoutIncludesOpaqueBars

这个值只是对以前的值的补充.默认情况下,该参数设置为 NO.如果状态栏不透明,则视图不会扩展以包含状态栏,即使您扩展视图以覆盖它(edgesForExtendedLayoutUIRectEdgeAll).

如果您将该值设置为 YES,这将允许视图再次进入状态栏下方.

如果有什么不明白的,写评论,我会回答.

iOS 如何知道使用什么 UIScrollView?

iOS 获取 ViewController 视图中的第一个子视图,即索引 0 处的子视图,如果它是 UIScrollView 的子类,则将解释的属性应用于它.

当然,这意味着 UITableViewController 默认工作(因为 UITableView 是第一个视图).

I have been reading a lot about iOS7 UI transition.

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.

解决方案

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

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.

Let see it with an example:

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

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.

This is the result:

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

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

And the result:


automaticallyAdjustsScrollViewInsets

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.

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.

This is when is set to NO:

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

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).

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.

How does iOS know what UIScrollView to use?

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.

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

这篇关于解释在 iOS7 中自动调整滚动视图插入、扩展布局包括OpaqueBars、边缘ForExtendedLayout 之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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