gpt4 book ai didi

ios - 解释 iOS7 中自动调整 ScrollView 插入、扩展布局包含不透明条、边缘ForExtendedLayout 之间的区别

转载 作者:IT老高 更新时间:2023-10-28 12:14:10 25 4
gpt4 key购买 nike

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

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

例如,我试图让我的 View Controller 在状态栏下方开始,但我无法实现。

最佳答案

从 iOS7 开始, View Controller 默认使用全屏布局。同时,您可以更好地控制 View 的布局方式,这可以通过这些属性完成:

edgesForExtendedLayout

基本上,您可以使用此属性设置 View 的哪些边可以扩展以覆盖整个屏幕。想象一下,您将 UIViewController 推送到 UINavigationController 中。当该 View Controller 的 View 布局时,它将从导航栏结束的位置开始,但此属性将设置 View 的哪些边(上、左、下、右)可以扩展以填满整个屏幕。

用一个例子来看看:

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

这里没有设置 edgesForExtendedLayout 的值,因此采用默认值 (UIRectEdgeAll),因此 View 扩展其布局以填满整个屏幕。

这是结果:

without edges for extended layout, the view fills the whole screen

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

现在,您要将该值设置为 UIRectEdgeNone,因此您要告诉 View Controller 不要扩展 View 以覆盖屏幕:

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

结果:

with edgesForExtendedLayout set, the view is just under the navigation


自动调整ScrollViewInsets

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

这里是这个属性派上用场的地方,如果你让 View Controller 自动调整 insets(将此属性设置为 YES,也是默认值)它会将 insets 添加到 table 的顶部,因此 table 将启动导航栏结束的地方,但滚动会覆盖整个屏幕。

这是设置为NO的时候:

the table will scroll over the whole screen, but starts out partially covered

是(默认情况下):

the table scrolls over the whole screen, and starts just under the navigation

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


extendedLayoutIncludesOpaqueBars

此值只是对先前值的补充。默认情况下,此参数设置为 NO。如果状态栏是不透明的,即使您将 View 扩展到覆盖状态栏, View 也不会扩展到包含状态栏(edgesForExtendedLayoutUIRectEdgeAll)。

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

如果有不清楚的地方,写评论,我会回答的。

iOS 如何知道要使用哪个 UIScrollView?

iOS 抓取 ViewController View 中的第一个 subview ,即索引 0 处的 subview ,如果它是 UIScrollView 的子类,则将解释的属性应用于它。

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

关于ios - 解释 iOS7 中自动调整 ScrollView 插入、扩展布局包含不透明条、边缘ForExtendedLayout 之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18798792/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com