透明导航栏下的UITableView

Wed*_*rda 0 uitableview ios autolayout swift

我正在尝试使用透明导航栏在 UIViewController 中布局表格视图。我已经完成了这一点,在我的自定义 UINavigationController 上使用此代码:

navigationBar.setBackgroundImage(UIImage(), for: .default)
navigationBar.shadowImage = UIImage()
navigationBar.isTranslucent = true
Run Code Online (Sandbox Code Playgroud)

在我的故事板上,我将 tableView 设置为将其边缘固定到安全区域,但顶部的除外,它固定在超级视图的顶部。

问题是我的 tableView 不是从屏幕顶部开始,而是导航栏仍然不透明。我检查了 tableView 插图,结果全部为零。我在这里做错了什么?

谢谢

Ker*_*ros 6

您可以尝试禁用滚动视图插图调整。

contentInsetAdjustmentBehavior从 iOS11 开始可用,因此您可以像下面的代码一样检查可用性:

if (@available(iOS 11.0, *)) 
{
    self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
} 
else 
{
    self.automaticallyAdjustsScrollViewInsets = NO;
}
Run Code Online (Sandbox Code Playgroud)