【问题标题】:UITableView under transparent navigation bar透明导航栏下的UITableView
【发布时间】:2018-08-27 15:45:24
【问题描述】:

我正在尝试在带有透明导航栏的 UIViewController 中布局表格视图。我已经在我的自定义 UINavigationController 上使用了这段代码:

navigationBar.setBackgroundImage(UIImage(), for: .default)
navigationBar.shadowImage = UIImage()
navigationBar.isTranslucent = true

在我的情节提要上,我将 tableView 的边缘固定到安全区域,但顶部除外,它固定在超级视图的顶部。

问题是我的 tableView 不是从屏幕顶部开始,但好像导航栏仍然不透明。我检查了 tableView 插图,所有内容都为零。我在这里做错了什么?

谢谢

【问题讨论】:

  • 确保edgesForExtendedLayout 至少包含.top。即设置viewDidLoad edgesForExtendedLayout = [.top] 并检查

标签: ios swift uitableview autolayout


【解决方案1】:

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

contentInsetAdjustmentBehavior 可从 iOS11 获得,因此您可以像以下代码一样检查可用性:

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

【讨论】:

  • 是的!,这行得通 :) 似乎 automaticallyAdjustsScrollViewInsets 已被弃用并且在 iOS 11.0 上什么也不做,所以 tableView.contentInsetAdjustmentBehavior 是要走的路。
猜你喜欢
  • 2014-08-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-21
相关资源
最近更新 更多