UIViewController:extendedLayoutIncludesOpaqueBars 和滚动视图偏移 [英] UIViewController: extendedLayoutIncludesOpaqueBars and scroll view offset

查看:20
本文介绍了UIViewController:extendedLayoutIncludesOpaqueBars 和滚动视图偏移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序的视图层次结构非常简单:UINavigationController 包含一个 UITableViewController.导航控制器的导航栏是不透明的,这会导致在导航转换期间表格视图出现一些奇怪的插入行为,请参见此处:

My app's view hierarchy is pretty straightforward: a UINavigationController contains a UITableViewController. The navigation controller's navigation bar is opaque, which causes some strange inset behavior of the table view during navigation transitions, seen here:

为了解决这个问题,我将 UITableViewController 上的 extendedLayoutIncludesOpaqueBars 设置为 true.这样做正确地扩展了导航栏下方的视图,但以一种我不太明白的方式改变了表视图的 contentOffset 的行为.将此属性设置为 true,表格视图的 contentOffset 的 Y 值报告它的偏移量高于导航栏当前高度(即滚动 table view 1pt,它报告它的 y-offset 是 -63pts).

To remedy this, I'm setting extendedLayoutIncludesOpaqueBars to true on the UITableViewController. Doing so properly extends the view beneath the navigation bar, but changes the behavior of the table view's contentOffset in a way that I don't quite understand. With this property set to true, the Y-value of the table view's contentOffset reports that it is offset higher than it should be by the current height of the navigation bar (i.e. scrolling the table view 1pt, it reports that its y-offset is -63pts).

这让我觉得导航控制器会自动管理滚动视图的 contentInset,就像它对半透明条所做的那样.但是我看不到任何证据表明滚动视图在 scrollViewDidScroll() 中设置了内容插入.即使在表视图控制器上将 automaticallyAdjustsScrollViewInsets 设置为 false,内容偏移量也不正确,因此似乎与插入无关.

This made me think that the navigation controller was automatically managing the scroll view's contentInset, like it does for translucent bars. But I couldn't see any evidence that the scroll view had content insets set in scrollViewDidScroll(). Even with automaticallyAdjustsScrollViewInsets set to false on the table view controller, the content offset wasn't right, so it seems it's nothing to do with the insets.

Apple 的关于 extendedLayoutIncludesOpaqueBars 的文档没有没有提到对滚动视图内容偏移的行为的任何影响.不幸的是,更改表格视图的 contentInset 并不能解决这个问题.

Apple's documentation about extendedLayoutIncludesOpaqueBars doesn't mention any effect on the behavior of a scroll view's content offset. Changing the contentInset of the table view unfortunately doesn't solve this.

我尝试更改表视图控制器的 edgesForExtendedLayout 属性以强制它扩展而不影响滚动视图,但似乎此属性对不透明条无效.

I tried changing the table view controller's edgesForExtendedLayout property to force it to extend without affecting the scroll view, but it seems this property is powerless against opaque bars.

extendedLayoutIncludesOpaqueBars 是否有一些隐藏的行为会导致滚动视图的内容偏移?或者这可能是一个错误?

Is there some hidden behavior with extendedLayoutIncludesOpaqueBars that borks up a scroll view's content offset? Or could this be a bug?

推荐答案

你试过了吗?

if #available(iOS 11, *) {
    tableView.contentInsetAdjustmentBehavior = .never
}

这篇关于UIViewController:extendedLayoutIncludesOpaqueBars 和滚动视图偏移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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