永远不会设置contentInsetAdjustmentBehavior

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了永远不会设置contentInsetAdjustmentBehavior相关的知识,希望对你有一定的参考价值。

我正在尝试在contentInsetAdjustmentBehavior == .neverUITableView中为viewDidLoad()设置ViewController,但无论我是以编程方式还是通过InterfaceBuilder进行,都会被忽略。

这是我得到的。该图像是TableView的标题。

我的导航栏顶部是透明的。

我希望带有图像的Header是这样的

任何帮助表示赞赏。谢谢

答案

enter image description here将imageView的topConstraint常量设置为-64

  • 为imageView的topConstraint创建一个Outlet
  • 声明变量topPadding(适用于iPhone X) @IBOutlet weak var topConstraint: NSLayoutConstraint! var topPadding:CGFloat = 0.0

并在viewDidload中使用以下代码

override func viewDidLoad() {
    super.viewDidLoad()

    self.navigationController!.navigationBar.setBackgroundImage(UIImage(), for: .default)
    self.navigationController!.navigationBar.shadowImage = UIImage()
    self.navigationController!.navigationBar.isTranslucent = true
    topConstraint.constant = -64
    if #available(ios 11.0, *) {
        let window = UIApplication.shared.keyWindow
        topPadding = (window?.safeAreaInsets.top)!
        topConstraint.constant = -(64+topPadding)
    }
}

Refer this sample project

以上是关于永远不会设置contentInsetAdjustmentBehavior的主要内容,如果未能解决你的问题,请参考以下文章