我正在尝试在 UIViewController 中使用透明导航栏布局表格视图。我已经完成了这一点,在我的自定义 UINavigationController 上使用此代码:
navigationBar.setBackgroundImage(UIImage(), for: .default)
navigationBar.shadowImage = UIImage()
navigationBar.isTranslucent = true
在我的 Storyboard 上,我将 tableView 设置为将其边缘固定到安全区域,但顶部的除外,它固定到超级视图的顶部。
问题是我的 tableView 不是从屏幕顶部开始,而是导航栏仍然不透明。我检查了 tableView 插图,结果全部为零。我在这里做错了什么?
谢谢
您可以尝试禁用滚动视图插图调整。
contentInsetAdjustmentBehavior
从 iOS11 开始可用,因此您可以像以下代码一样检查可用性:
if (@available(iOS 11.0, *))
{
self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
else
{
self.automaticallyAdjustsScrollViewInsets = NO;
}
Swift 5.8.1 变体:
if #available(iOS 11.0, *) {
tableView.contentInsetAdjustmentBehavior = .never
} else {
automaticallyAdjustsScrollViewInsets = false
}