gpt4 book ai didi

仅限 iOS 11 : Navigation bar label off on top

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:22:13 25 4
gpt4 key购买 nike

IOS 11 导致主标签从顶部移动一点点,而不是保持在顶部。该问题仅出现在 IOS 11 上。对于不同的 IOS,一切看起来都正常。

带有设置标题的代码示例:

    private func setHeader(agentName: String = "", isTyping: Bool = false) -> Void {
if (agentName.isEmpty) {
self.containerViewController?.navigationItem.titleView = nil
} else {
let headerView: UIView = {
let rect = CGRect(x: 0, y: 0, width: 320, height: 44)
let uiview = UIView(frame: rect)

return uiview
}()


let headerLabel: UILabel = {
let label = UILabel(frame: CGRect(x: 0, y: 0, width: headerView.frame.width, height: 20))
label.font = UIFont.systemFont(ofSize: 18)
label.textAlignment = .center
label.translatesAutoresizingMaskIntoConstraints = false
return label
}()

let subheaderLabel: UILabel = {
let label = UILabel(frame: CGRect(x: 0, y: 0, width: headerView.frame.width, height: 12))
label.font = UIFont.systemFont(ofSize: 12)
label.translatesAutoresizingMaskIntoConstraints = false
label.text = self.title
return label
}()


headerView.addSubview(headerLabel)
headerView.addSubview(subheaderLabel)

let viewsDictionary = ["header": headerLabel, "subheader": subheaderLabel]
headerView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|[header]|", options: NSLayoutFormatOptions(), metrics: nil, views: viewsDictionary))
headerView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|[subheader]|", options: NSLayoutFormatOptions(), metrics: nil, views: viewsDictionary))
headerView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|[header(20)]-[subheader]", options: [], metrics: nil, views: viewsDictionary))

self.containerViewController?.navigationItem.titleView = headerView

}
}

Label off

最佳答案

从 iOS 11 开始,添加到工具栏的 View 现在使用自动布局进行布局。您应该在 headerView 上添加大小限制。例如:

headerView.widthAnchor.constraintEqualToConstant(320.0).isActive = true
headerView.heightAnchor.constraintEqualToConstant(44.0).isActive = true

否则,自动布局将使用标题 View 的固有内容大小,这可能不是您所期望的。

有关更多信息,请参阅 WWDC 2017 session Updating your app for iOS 11 .

关于仅限 iOS 11 : Navigation bar label off on top,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46793954/

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