gpt4 book ai didi

ios - contentInsetAdjustmentBehavior 从未设置

转载 作者:行者123 更新时间:2023-11-28 07:41:19 25 4
gpt4 key购买 nike

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

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

Here is what I get. The image is the header of the TableView.

顺便说一下,我的导航栏位于透明的顶部。

我希望带图片的Header是这样的

expected behavior

任何帮助表示赞赏。谢谢

最佳答案

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

关于ios - contentInsetAdjustmentBehavior 从未设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52163301/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com